Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Binary Tree

AT87
AT87 


I am writing a couple of classes for a Binary Tree program which are attached below. The node class and Tree class are the ones I have been working on and the TreeDemo class has been provided to us and absolutely cannot be altered in any way. I have spent several hours already trying to work on these two classes but I am having trouble with the recursion process and some methods. I have set up a lot of the assignment so I don't anticipate much more coding but just a handful of methods such as a Search method, inOrder, postOrder, preOrder, and toString. You may change anything you need to in the node.java class or tree.java class, just not the treedemo.java main program. The instructions are also attached. Attachments Tags Clarifications

Answers

Program Code

mariobeka
mariobeka 



Answer to the questioned asked. Attachments
Tree.java (2 K) Download Preview
> 0) { // look right if (loc.right != null) loc = loc.right; else { loc.right = new TreeNode(d); break; } } else break; // found! Don't insert } } // method to search for a specific word in the tree public void search(String string) { TreeNode t = root;

TreeNode.java (1 K) Download Preview
d) { // construct leaf node data = d; left = right

TreeDemo.java (1 K) Download Preview
new Random(); // Initialize Random Tree myTree = new Tree(); // Initialize the Tree for (int addLoop = 0; addLoop < 16; addLoop++) // Loop to add items to the Tree myTree.insert(numbers[rand.nextInt(16)]); // Method call to the tree to insert nodes System.out.println("---Searches---"); // Start

Screenshots
Purchase Answer