aspose file tools*
The moose likes Beginning Java and the fly likes how do you remove a node from a binary tree? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how do you remove a node from a binary tree?" Watch "how do you remove a node from a binary tree?" New topic
Author

how do you remove a node from a binary tree?

Dmitri Makovetskiy
Ranch Hand

Joined: Jun 21, 2010
Posts: 128




did i do it right. first, make a function to check the head , whether to remove it, and then call for a function to remove nodes from the body, and transfer the chain underneath to another node..

one thing that i didnt understand is why do you need addUnit(right), addUnit(left) .. in the order described in the remove functions?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why would you add a node to both the left and right nodes?

And the usual advice: write out the algorithm, draw a picture, whatever helps you understand. Run through a few cases:

- No nodes
- A single node
- A few nodes

That should be enough to make the algorithm understandable.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(I have deleted your post in which you question my usefulness so that you will not be banned from the site. Please refrain from insulting the staff and being inflammatory, and recognize that not only *am* I helping you, I am the *only* one helping you. Unfortunately, you refuse to help *yourself*, which is pretty much one of the only rules of JavaRanch, along with BeNice. If you fail to BeNice one more time, the ban hammer will be wielded.)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how do you remove a node from a binary tree?