C 为什么插入后左节点的键丢失?
我无法使用Insert_节点插入具有相应键的节点,也无法找出问题所在。 Keys是我前面创建的整数数组。 代码如下: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
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)
,)