permaculture playing cards*
The moose likes Beginning Java and the fly likes Binary search tree remove node Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Binary search tree remove node" Watch "Binary search tree remove node" New topic
Author

Binary search tree remove node

Brian Lennon
Greenhorn

Joined: Mar 18, 2013
Posts: 3

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


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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.
Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

That code is not compilable, so whatever you are running is not the code you posted.
Brian Lennon
Greenhorn

Joined: Mar 18, 2013
Posts: 3

Sorry Mack I just had a look and here is the revised code


Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Binary search tree remove node
 
Similar Threads
Binary Search Tree
A question about generics
scapegoat tree rebuilding...please help!
Compilation error.
Draw binary tree structure