Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2006, 9:12 PM   #11
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
there is just one problem. The deleted value is the root value. But to delete the root you have to delete the last entry and then replace the value of the root with the value of the last entry. When it says what value is deleted it prints out the last entry instead of the root. So really i just need to change it to print out the value of the root instead of the value of the last entry. Not quite sure how to do that though because you have it printing out the root entry but it says its the last? Other than that it works.
cwl157 is offline   Reply With Quote
Old Apr 6th, 2006, 9:16 PM   #12
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
There is still one hole. If i just insert a root value and then delete it it does not print out the root as being deleted or if its just a root and its 2 children i get a segmentation fault when trying to delete but it happened one time like that and not another
cwl157 is offline   Reply With Quote
Old Apr 6th, 2006, 9:33 PM   #13
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
alright how do i account for the case of only a root value because when there is only a root value it does not print out that it is deleting it. It deletes fine it just does not print out the value. I assume an if statement of
if(root->left->getValue() == NULL && root->right->getValue() == NULL)
    cout << "Deleted Value = " root->getValue();
would work but where do i put it? Just next to the other printing thing in the deleteSpot method?
cwl157 is offline   Reply With Quote
Old Apr 6th, 2006, 10:21 PM   #14
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
You have a special case for the root node already in your code.
    else if(counter == 1)
      {
        delete root;
	      root = NULL;
      }
    else
Why not just print it there before you delete it?

In the other case, where there is more than just the root node, print the root node before you find and delete the last node.
The Dark is offline   Reply With Quote
Old Apr 6th, 2006, 10:46 PM   #15
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
o yea... That worked. I also get a segmentation fault if i make a tree and then delete every node until tree is empty and then try to re insert values into the tree and try to delete one of them. I do not think that was part of the requirement so its not that big of a deal but if its possible to fix it it would be appreciated.
cwl157 is offline   Reply With Quote
Old Apr 6th, 2006, 11:45 PM   #16
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
When you get a situation like this, look at what code is run in this particular case and not in the other cases you have tried.
In this case, the code to delete the root node is run. One thing that code does not do is decrement the counter, so your counter variable is now out of synch with your tree.
The Dark is offline   Reply With Quote
Old Apr 6th, 2006, 11:54 PM   #17
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 333
Rep Power: 4 cwl157 is on a distinguished road
yes Now it works perfectly A million thank yous for all the help it is beyond greatly apreciated.
cwl157 is offline   Reply With Quote
Old Apr 7th, 2006, 2:35 AM   #18
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Wow Peter, you helped pretty amazingly, it suprises me you didn't get tiresome of having to read 10 posts after another. "My respect you have" says Yoda.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 7th, 2006, 2:38 AM   #19
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 825
Rep Power: 4 The Dark is on a distinguished road
It was interesting, I'd never done a min heap that way before, so I was learning as I went.
The Dark is offline   Reply With Quote
Old Apr 7th, 2006, 2:45 AM   #20
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by The Dark
It was interesting, I'd never done a min heap that way before, so I was learning as I went.
If you decide to rewrite it one day, then please do make a thread and show us the code, I would be interested in how you would have done it. Or would you have done it the same as this guy (cwl157)? (When not using arrays, that is.)
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC