我遇到了这种方法来清除二叉搜索树。代码在教科书中给出。为什么必须最终创建和删除节点temp?为什么不删除subroot而不是使其为null?
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;
}