题目
CIS-279-OLH-CRN47413 Quiz: Chapter 7
单项选择题
Which XXX completes the leaf removal case in the C++ BinarySearchTree class's Remove() function? if (currentNode->left == nullptr && currentNode->right == nullptr) { if (parent == nullptr) { root = nullptr; } else if (parent->left == currentNode) { parent->left = nullptr; } else { parent->right = nullptr; } XXX return true; }
查看解析
标准答案
Please login to view
思路分析
Question restatement: In the given C++ BinarySearchTree Remove() function, for the leaf node case (when currentNode has no children), which code should fill the placeholder XXX?
Option analysis:
- The provided answer choice is: delete currentNode;
This is appropriate because, when a node is a leaf, there are no children to preserve or reattach. After disconnecting currentNode from its parent (by setting the corresponding parent pointer to nullptr), we must free the memory occupied......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
When memory allocated with the C malloc function is no longer needed, that memory should be returned to the system immediately by calling the C __________ function.
In a consumer society, many adults channel creativity into buying things
Economic stress and unpredictable times have resulted in a booming industry for self-help products
People born without creativity never can develop it
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!