Closed Thread
Results 1 to 2 of 2

Thread: How to write the code to delete the whole binary search tree ??

  1. #1
    Join Date
    Nov 2007
    Posts
    11
    Rep Power
    0

    How to write the code to delete the whole binary search tree ??

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    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).
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. problem with a binary search tree
    By hadas_zr in forum C and C++
    Replies: 3
    Last Post: 07-14-2011, 07:43 AM
  2. Tail Recursion (Binary Search Tree height() implementation)
    By CoryG89 in forum General Programming
    Replies: 1
    Last Post: 03-30-2011, 07:08 AM
  3. Binary tree
    By tomy in forum C and C++
    Replies: 6
    Last Post: 08-16-2010, 11:58 PM
  4. Replies: 7
    Last Post: 06-18-2010, 12:17 AM
  5. Binary Search Tree Construction Help
    By ahmed in forum General Programming
    Replies: 7
    Last Post: 02-10-2010, 02:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts