c - 从数组创建二叉树的问题

标签 c arrays pointers recursion binary-tree

我在使用构建二叉树的递归函数时遇到问题。

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/

相关文章:

javascript - 在对象内的对象内创建数组

javascript - 如何在对象数组中搜索 - javascript

c++ - 请指教以下C++语法及其意义! (可能是重载的情况)

c - 比较字符串中的字母

javascript - 将字节数组写入文件 JavaScript

c - 如何最好地检查 C 库依赖性?

c - 使用指针 C 从函数返回数组

c - 警告 : assignment from incompatible pointer type [-Wincompatible-pointer-types] qt1. 函数 = &H1

将 void 指针分配给非 void 指针的 C99 警告?

c - 使用 Windows API 将无模式对话框作为子窗口嵌入