이 방법을 통해 이진 검색 트리를 정리했습니다. 코드는 교과서에 나와 있습니다. 결국 노드 temp를 생성하고 삭제해야하는 이유는 무엇입니까? 서브 루틴을 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;
}
힌트 :'sub_root'는 참조로 전달됩니다. 이것은 ** 글자 그대로 ** 10 분 전에 요청되었습니다 : [link] (http://stackoverflow.com/questions/16255235/using-free-on-ac-struct/16255294#16255294) –
@ H2CO3 그래, 왜 store sub_root sub_root-> left 또는 right를 전달하고 sub_root는 전달하지 않으므로 temp로 변경하십시오. –
@Armin'sub_root = NULL;'문이 있기 때문에. –