I'm writing the class for the N-ary tree and I need to finish it with a destructor. For my tree, all I do is insert, traverse, print, and destruct it basically. The part of the code dealing with it will be something like:
while (/*not at end of input*/)
{ Tree now;
// insert into tree
// print
}
It would be vital to have a destructor in this case right cause it dies when it hits the closing bracket. Right?
In most examples I've seen, most people just write something like, delete root;
and leave it at that. I was under the impression that was a poor way to handle it cause all the other stored nodes are still there, you just can't reach them.
So, is that the best way to handle it or should I write some kind of function that clears each node until only contains the root and then delete it?