Results 1 to 4 of 4
Thread: Help with binary trees please
- 11-27-2012, 06:37 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 30
- Rep Power
- 0
Help with binary trees please
I have created 3 classes, binaryTreeTraversal, this has four traversal methods which also has a method to print out to the screen.
I have binaryTreeNode that has my leftChild, rightChild and Object element.
I also have an arrayQueue that stores the nodes etc..
What I am trying to do to test it is to automatically input data, (e.g A+B) and print it in each traversal.
The output I get is :Java Code:public class TestBed { public void TestBed() { binaryTreeTraversal traversal = new binaryTreeTraversal(); BinaryTreeNode t = new BinaryTreeNode(); t.leftChild = new BinaryTreeNode(); t.rightChild = new BinaryTreeNode(); t.rightChild.element = new BinaryTreeNode(); t.leftChild.element = new BinaryTreeNode(); Object element = "A+B"; //Don't think this is right, but thats what I want to print out traversal.inOrder(t); //Calls inOrder and print out traversal.levelOrder(t); //Calls levelOrder and prints out traversal.postOrder(t); //Calls postOrder and prints out traversal.preOrder(t); //Calls preOrder and prints out } }
BinaryTreeNode@375ef3ab
null
BinaryTreeNode@3acf7bf3
null
BinaryTreeNode@375ef3ab
BinaryTreeNode@3acf7bf3
BinaryTreeNode@375ef3ab
BinaryTreeNode@3acf7bf3
null
null
BinaryTreeNode@375ef3ab
BinaryTreeNode@3acf7bf3
I hope this makes sense and thank you to anybody who can help.
- 11-27-2012, 07:04 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Help with binary trees please
Your BinaryTreeNode class doesn't implement a toString() method, that's why you get the funny output (generated by Object.toString()). I don't understand your test code, e.g. can an element part of a node be another binary tree? According to your code it can, according to my book it can't.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-27-2012, 07:27 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 30
- Rep Power
- 0
Re: Help with binary trees please
Thanks very much :)
When you say an element part of a node do you mean :
t.rightChild.element = new BinaryTreeNode();
t.leftChild.element = new BinaryTreeNode();
- 11-27-2012, 07:34 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: Help with binary trees please
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Algorithms to compare None-Binary Trees
By memo.baghdady in forum New To JavaReplies: 0Last Post: 07-24-2012, 01:56 PM -
Binary Search Trees
By kraigballa in forum New To JavaReplies: 2Last Post: 04-10-2012, 04:31 PM -
HELP!! Binary trees
By Get_tanked in forum New To JavaReplies: 4Last Post: 03-24-2011, 06:09 PM -
Binary trees
By girgishf in forum Advanced JavaReplies: 15Last Post: 11-20-2010, 04:29 PM -
Tutorial on Binary Search Trees
By JordashTalon in forum New To JavaReplies: 3Last Post: 03-18-2009, 03:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks