File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Binary Search Tree Freezes

 
Angela Truce
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Grant Gainey
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic