我在使用构建二叉树的递归函数时遇到问题。
tree_link tree_from_array_preorder(Item arr[], int N)
{
int pos =0;
int * pos_ptr=&pos;
//struct tree_struct treeOfLife;
if((N<1)|| (arr[0]==0))
return NULL;
tree_link root=new_tree_link(arr[pos]);
root->left=tree_from_array_preorder_aux(arr, pos_ptr, N);
root->right=tree_from_array_preorder_aux(arr, pos_ptr, N);
return root;
}
tree_link tree_from_array_preorder_aux(Item arr[], int *pos, int N)
{
if(arr[pos]==0)
return NULL;
tree_link root= new_tree_link(arr[pos]);
(pos)+=1;
root->left=tree_from_array_preorder_aux(arr, pos, N);
root->right=tree_from_array_preorder_aux(arr, pos, N);
return root;
}
我不断收到有关 aux 函数和我对其调用之间类型冲突的错误。我很确定我的指针声明和我对所述指针的引用都搞砸了。如有任何帮助,我们将不胜感激,并感谢您抽出宝贵的时间。
最佳答案
我忘记在我用于该程序的添加的 .h 头文件中声明原型(prototype)。 … – JustaRedShirt
关于c - 从数组创建二叉树的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33851377/