【发布时间】:2017-04-12 15:00:13
【问题描述】:
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。
【问题讨论】:
-
考虑是否通过值或引用传递根,具体取决于您的语言。见:stackoverflow.com/questions/32492184/binary-tree-root-is-null
-
谢谢。你是对的。
标签: binary-tree