my dog learned polymorphism*
The moose likes Java in General and the fly likes Binary Search Tree Freezes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Binary Search Tree Freezes" Watch "Binary Search Tree Freezes" New topic
Author

Binary Search Tree Freezes

Angela Truce
Ranch Hand

Joined: Nov 30, 2005
Posts: 47
hi,
Ive written an ADD method for a binary search tree. This is only part done and looks at the leftest side of the tree. When i try to execute it, it doesnt do anything (my applet wont load to show the tree).

Can anyone see why?

code:





thanks.
Shri Rohit Kumar
Greenhorn

Joined: Apr 27, 2006
Posts: 11
Greetings there,
well i guess its too late for a reply, but as they say it, its never too late :-)

so, while reading your code, what seems strange is that you are reusing the root node, as a temporary node.
in the check of whether the tree is empty, when the code reaches the root!=null you have used the root node as a temporary node.
so rather, first use a temp node to iterate through the whole tree(not the root node!) and maybe it'll lead you some where.
also your root objects class structure might also be needed to see what's in there too :-)

hope thi helps,

re
rohit.


Namaste, i honour the spirit in you which is also in me.
Grant Gainey
Ranch Hand

Joined: Oct 16, 2005
Posts: 65
MMm, I think Rohit is close.

I'm assuming that rootroot is a class-variable that is intended to hold the root of your tree. If so, then your code overwrites root as it traverses the tree. I suspect this is bad.

Try this - in the else clause, before the while (cont) {, add a line Then, replace every instance of root inside the while with currentNode. See if that changes the behavior.

Good luck,
Grant


In Theory, there is no difference between theory and practice.<br />In Practice, there is no relationship between theory and practice.
 
Don't get me started about those stupid light bulbs.
 
subject: Binary Search Tree Freezes