jdennison
asked on
Binary Trees
I am trying to implement a Binary Tree class in JAVA. My code so far goes something like this ..
class BTree{
private int Data;
private BTree LeftNode, RightNode;
private void insert(int NewItem, BTree TreeNode){
.
.
.recursive code here,
e.g if (NewItem>TreeNode.Data)
TreeNode.insert(NewItem,Tr eeNode.Rig htNode);
}
private void InOrder(BTree Node){
if (Node == null) return;
else
Node.inorder(Node.Left);
System.out.println(Node.Da ta+"\n");
Node.inorder(Node.Right);
}
I can get it to compile, but when I use BTree it doesn't seem to work. I am confused about how to construct a new instance - should the new object somehow be assigned a null value.
Any help - especially code or a link to java code explaining how to implement a simple BTree like above would be much appreciated. The same goes for linked lists.
class BTree{
private int Data;
private BTree LeftNode, RightNode;
private void insert(int NewItem, BTree TreeNode){
.
.
.recursive code here,
e.g if (NewItem>TreeNode.Data)
TreeNode.insert(NewItem,Tr
}
private void InOrder(BTree Node){
if (Node == null) return;
else
Node.inorder(Node.Left);
System.out.println(Node.Da
Node.inorder(Node.Right);
}
I can get it to compile, but when I use BTree it doesn't seem to work. I am confused about how to construct a new instance - should the new object somehow be assigned a null value.
Any help - especially code or a link to java code explaining how to implement a simple BTree like above would be much appreciated. The same goes for linked lists.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER