Forums Register Login

Binary search tree remove node

+Pie Number of slices to send: Send
Hi if someone can help me it would be great!!! Basically I have a remove method which removes a specified node but what the method is doing is deleting the entire tree. I tried debugging but I cant see the problem.
Here is my code...


+Pie Number of slices to send: Send
Hi, and welcome to the Ranch!

You say you tried debugging your code, but I don't see any println() calls that would be useful for that. Your first step should be to add a bunch to the remove method, to show what's happening at each step, what it's removing, and what the tree looks like before and after.
+Pie Number of slices to send: Send
That code is not compilable, so whatever you are running is not the code you posted.
+Pie Number of slices to send: Send
Sorry Mack I just had a look and here is the revised code


+Pie Number of slices to send: Send
You are assigning head.right = tail in your remove routine and when it goes to traverse() there is nothing to traverse. You are making t = tail on line 113. You essential disconnected the whole tree as far as traverse() is concerned. I think you need to start over on your removal routine and think through what you need to do step by step and write it down in pseudo code before you code it. Other than that, there are probably hundreds of examples on the Internet of binary tree operations you should look at.
It's feeding time! Give me the food you were going to give to this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5210 times.
Similar Threads
scapegoat tree rebuilding...please help!
A question about generics
Binary Search Tree
Compilation error.
Draw binary tree structure
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 03:01:36.