Skip to content

Conversation

lixiang2017
Copy link

Utilities下,BinaryTree.h和BinaryTree.cpp中的void DestroyTree(BinaryTreeNode* pRoot)参数要加引用,即改为void DestroyTree(BinaryTreeNode*& pRoot)。
因为对指针有释放内存,并赋值为nullptr。只有加上引用,赋值才能生效。否则会成为野指针。

void DestroyTree(BinaryTreeNode*& pRoot);函数中对指针进行了修改,并希望保存,所以要加上&。否则修改的结果不生效,成为野指针。
void DestroyTree(BinaryTreeNode*& pRoot)函数中会对指针进行修改。加上引用,修改才能生效,否则成为野指针,无法达到销毁树的目的。
@Michael-Xbins
Copy link

不错

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants