Code on Binary Trees

public class Tree {

private static Node root;
public Tree(int d)
{
root = new Node(d);
}
public Node getRoot()
{
return root;
}
public void level_order_insert(Node r, String s, int start, int size)
{
int left = 2*start+1;
int right = 2*start+2;
if(left > size || right > size)
{
return;
}
if (root.getLeft() == null && root.getRight() == null)
{
if (left < size)
{
root.setLeft(new Node(s.charAt(left)));
}
if(right < size)
{
root.setRight(new Node (s.charAt(right)));
}
}
level_order_insert(root.getLeft(), s, left, size);
level_order_insert(root.getRight(), s, right, size);

}
public Node leftMost(Node root)
{
Node node = root;
while(node.getLeft()!= null)
{
node = node.getLeft();
}
return node;

}

public Node rightMost(Node root)
{
Node node = root;
while(node.getRight()!= null)
{
node = node.getRight();
}
return node;

}

public int height(Node root)
{
if (root == null)
return 0;
else
return (int) (1 + Math.max((double) height(root.getLeft()), (double) height(root.getRight())));
}

public int count(Node root)
{
int c = 1;
if (root.getLeft()!= null)
c = c + count(root.getLeft());
if (root.getRight()!= null)
c = c + count(root.getRight());
return c;

}
public void preOrder(Node root)
{

System.out.println(root.getData());
if(root.getLeft() != null)
preOrder(root.getLeft());
if(root.getRight()!= null)
preOrder(root.getRight());

}

public void inOrder(Node root)
{

if(root.getLeft() != null)
inOrder(root.getLeft());
System.out.println(root.getData());
if(root.getRight()!= null)
inOrder(root.getRight());

}

public void postOrder(Node root)
{

if(root.getLeft() != null)
postOrder(root.getLeft());
if(root.getRight()!= null)
postOrder(root.getRight());
System.out.println(root.getData());

}

public static void main(String[] args) {
// TODO Auto-generated method stub

Tree t = new Tree(1);
t.getRoot().setLeft(new Node(4));
t.getRoot().getLeft().setLeft(new Node(3));
t.getRoot().getLeft().setRight(new Node(6));
t.getRoot().setRight(new Node(5));
t.getRoot().getRight().setLeft(new Node(8));
t.getRoot().getRight().setRight(new Node(9));

System.out.println(t.count(root));
// Tree k = new Tree(“h”);

}

}

=====node====

 
public class Node {
private int data;
private Node left;
private Node right;

public Node(int d)
{
data = d;
left = null;
right = null;
}

public void setLeft(Node n)
{
left = n;
}
public void setRight(Node r)
{
right = r;

}
public void setData(int d)
{
data = d;
}
public Node getLeft()
{
return left;
}
public Node getRight()
{
return right;
}
public int getData()
{
return data;
}
}