Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C and C++

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-21-2007, 11:47 AM
worried_student worried_student is offline
Newbie
 
Join Date: Nov 2007
Posts: 11
Credits: 0
Rep Power: 0
worried_student is on a distinguished road
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-23-2007, 10:09 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,453
Last Blog:
wxWidgets is NOT code ...
Credits: 761
Rep Power: 28
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

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).
__________________

To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write image data to binary PGM file format(P5)? tommy_chai C and C++ 5 03-30-2008 05:47 AM
How to write a Simulator for SML code debug C and C++ 3 10-30-2007 11:14 AM
How to write such code??? stephen0606 C and C++ 5 10-10-2007 08:24 PM
need help with simple C++ TicTacToe game with AI flupke1 C and C++ 11 08-14-2007 10:27 AM


All times are GMT -5. The time now is 11:02 PM.

Contest Stats

Xav ........ 1276.19
MeTh0Dz|Reb0rn ........ 1048.58
marwex89 ........ 869.98
morefood2001 ........ 868.04
John ........ 865.15
WingedPanther ........ 761.06
Brandon W ........ 684.87
chili5 ........ 294.12
Steve.L ........ 216.18
dargueta ........ 192.86

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 81%

Ads