我遇到了这种清除二叉搜索树的方法。代码在教科书中给出。为什么最终必须创建和删除节点临时?为什么不删除子根而不是使其为空?
void Binary_tree<Entry> :: recursive_clear(Binary_node<Entry> * &sub_root)
/* Post: The subtree rooted at sub_root is cleared. */
{
Binary_node<Entry> *temp = sub_root;
if (sub_root == NULL) return;
recursive_clear(sub_root->left);
recursive_clear(sub_root->right);
sub_root = NULL;
delete temp;
}