【发布时间】:2017-10-12 15:25:07
【问题描述】:
有谁知道如何将值保存到左侧或右侧的二叉树中? 例如我们有 2 个结构体:
struct A
{
int a;
struct A *left;
struct A *right;
}
struct B
{
A *root;
}
我们有一个函数:
void insert(B *tree, int value)
{
if(tree== NULL)
{
tree= (B*) malloc (sizeof(B));
}
else if(tree!=NULL)
{
tree->root->a = value;
tree->root->left = NULL;
tree->root->right = NULL;
}
现在我们有了根... 但是如何初始化左右两边的值呢?
else if(tree->apointer->a< value)
{
tree->root->left = value // with & wont work cause is a pointer to integer
}
有人知道吗??
提前致谢
【问题讨论】:
-
除非你是在站在火车上的智能手机上使用 vi,否则你的编码风格绝对应受谴责。
-
请联系您的老师。您在一些核心概念方面存在根本问题,需要在教学环境中解决,而不是在问答网站中解决。
标签: c insert binary-tree binary-search-tree