Hello. I'm working on basic skills of Tree now. But I have no idea how to creat a client for this class to work. Could anyone show me how to write a client for this class? ------------------------------------------ Using this class, 1> I would like to creat a binary search tree with the following set of data : 15, 23, 8, 1, 2, 16
2> I would like to delete the node containg 2
3> I would like to print the value stored in each node with an pre-order traversal ---------------------------------- Here is my class I wrote.
A: When posting code, you should use "code tags." These preserve formatting, and make your code easier to read. The tags are right below the message box.
Question about this section: tail.getLeft(newNode) doesn't make any sense- getLeft doesn't take any arguments. I assume you mean that to be setLeft. Try it with that fix, and see if there are still problems.
I've heard it takes forever to grow a woman from the ground
Joined: Mar 19, 2005
Thank you for the advice, nick. As you pinpointed, it should have been
But...I still have two problems.
1. I have no idea how to creat a constructor for "delete" option
2. I have no idea how to creat a client using these classes. I mean...I don't know how to make this run. I read through several books, but I was not able to find anything about compiling this "Tree" thing.
If you could give me some help with those problems, I will be truely grateful. Thank you. [ March 19, 2005: Message edited by: Taylor Woods ]
Did you write this TreeNode class yourself? If so you should understand how each method works. To write a client for the class, start with "public static void main(String args)". Then in the main() method write the code to accomplish each of the tasks you described above. If you encounter problems, feel free to come back with specific questions. Typically you should post the code you have tried (in this case the main() method). Also include compiler errors and output, if any.
When you typed in the TreeNode code from your book, did you type in all of the brackets carefully?
Check particularly the insert method.
There is another error in the insert method also. You have:
which should probably be,
Joined: Mar 19, 2005
Thanks Horatio...I fixed the code as you showed. But...now, it shows so many errors that says
"TreeNode.java:68: cannot find symbol symbol : variable tail location: class TreeNode if (num < tail.getValue())"
"TreeNode.java:69: cannot find symbol symbol : variable tail location: class TreeNode tail.setLeft(newNode);"
"TreeNode.java:89: cannot find symbol symbol : variable root location: class TreeNode insert(15, root);" <---this error message for every number I used "insert"
"TreeNode.java:97: cannot find symbol symbol : variable tree location: class TreeNode tree.preOrder();"
Error messages are as shown above. Could you show me the way to fix these?
Oh...and it will be great if you can also show me the way to creat a constructor to delete a node from the tree.
Joined: Feb 23, 2005
So that we can help you, please post the updated code for the TreeNode class. Remember to use the CODE tags (click the 'CODE' button at the bottom of the window and paste your code inbetween the two tags).