Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么插入后左节点的键丢失?_C_Algorithm_Data Structures_Binary Tree_Nodes - Fatal编程技术网

C 为什么插入后左节点的键丢失?

C 为什么插入后左节点的键丢失?,c,algorithm,data-structures,binary-tree,nodes,C,Algorithm,Data Structures,Binary Tree,Nodes,我无法使用Insert_节点插入具有相应键的节点,也无法找出问题所在。 Keys是我前面创建的整数数组。 代码如下: Node* Create_node(int x) { Node* newNode = (Node*)malloc(sizeof(Node)); newNode->key = x; newNode->left = NULL; newNode->right = NULL; return newNode; } Node* Ins

我无法使用Insert_节点插入具有相应键的节点,也无法找出问题所在。 Keys是我前面创建的整数数组。 代码如下:

Node* Create_node(int x)
{
    Node* newNode = (Node*)malloc(sizeof(Node));
    newNode->key = x;
    newNode->left = NULL;
    newNode->right = NULL;
    return newNode;
}
Node* Insert_node(Node** proot, int x)
{
    Node* root = *proot;
    if(root == NULL)
    {
        root = Create_node(x);
    }
    return root;
}
int main()
{
    Node* root = Create_node(keys[0]);
    Insert_node(&root->left,keys[1]);
    printTree(root);
    return 0;
}

返回新根,但不存储它。您还可以传递一个指向节点指针的指针,这样您就可以通过该poiner更新链接,但您不能这样做。(这将是
*proot=CreateNode(x)
,)