1
void Btree<T>::InsertNode2(T data, BtreeNode* root)
{
if (root==NULL)
{
root = new BtreeNode (data);
return ;
}
if (data <= root->data)
InsertNode2(data, root->leftchild);
else
InsertNode2(data, root->rightchild);
}
为什么它不是正确的?根目录无法正确分配。在调用函数后,它仍然是NULL。如何通过递归在二叉树中插入元素?
考虑,如果你是按值或引用传递根,根据您的语言。请参阅:http://stackoverflow.com/questions/32492184/binary-tree-root-is-null – DragonMoon
谢谢。你是对的。 – user7857293