Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilities下,BinaryTree.h和BinaryTree.cpp中的DestroyTree()参数要加引用 #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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