![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#12 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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
|
|
|
|
|
|
#13 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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(); |
|
|
|
|
|
#14 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
You have a special case for the root node already in your code.
else if(counter == 1)
{
delete root;
root = NULL;
}
elseIn the other case, where there is more than just the root node, print the root node before you find and delete the last node. |
|
|
|
|
|
#15 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#16 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#17 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 333
Rep Power: 4
![]() |
yes Now it works perfectly A million thank yous for all the help it is beyond greatly apreciated.
|
|
|
|
|
|
#18 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#19 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
It was interesting, I'd never done a min heap that way before, so I was learning as I went.
|
|
|
|
|
|
#20 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|