Dear all
I'd like to ask how to write the functions (class destructor)to delete the whole binary search tree which is implemented as class objects, each node was dynamically allocated by pointers. How to write a function to (dynamically) destroyed all the nodes? (to become empty tree), i am an inexperienced c++ code writer
Thank you very much
Basically, in the destructor you need to check both left and right children for NULL, and if not NULL then tell them to delete (which will result in a recursive cascade of freed nodes).
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks