void DeleteTree(Tree*root) { while (root != NULL) { DeleteTree(root->left); DeleteTree(root->right); root = NULL; delete root; } 

Closed due to the fact that the essence of the question is not clear to the participants of Jean-Claude , Suvitruf , cheops , Kromster , ߊߚߤߘ 16 Nov '17 at 9:38 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Agde tree itself? - 0xdb

3 answers 3

Look at your last two lines. First, you null the pointer, and then delete the data on it, that is, on null. On good, they need to be rearranged in places. Well, while not needed.

 void DeleteTree(Tree*root) { if(root != NULL) { DeleteTree(root->left); DeleteTree(root->right); delete root; root = NULL; } } 
  • And while here works like a normal if. - Mikhailo

It should be like this:

 void DeleteTree(Tree*root) { if (root != NULL) { DeleteTree(root->left); DeleteTree(root->right); delete root; } } 

And you first reset root, and then delete it.

    Hope this is ochepyatka?

     root = NULL; delete root; 

    And you still delete the root first (freeing memory), and then reset it, and do not try to delete the NULL pointer?