Link to home
Start Free TrialLog in
Avatar of jdennison
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,TreeNode.RightNode);
}

private void InOrder(BTree Node){
if (Node == null) return;
      else
      Node.inorder(Node.Left);
      System.out.println(Node.Data+"\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.
Avatar of jdennison
jdennison

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of aleshka
aleshka

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial