trying to finish a code given by sir which was to add the preorder and post order in thr tree but i am getting an error with the preorder so need help.
public class BinaryTree {
BinaryTree left;
BinaryTree right;
int value;
public BinaryTree(int v){
value= v;
}
public void insert(int v){
if (v < value){
if (left == null)
left = new BinaryTree(v);
else
left.insert(v);
}
else if (v >value){
if (right == null)
right = new BinaryTree(v);
else
right.insert(v);
}
}
public void inorder(){
if(left !=null)
left.inorder();
System.out.println(value);
right.inorder();
}
public void preorder(){
if(value !=null)
System.out.println(value);
left.preorder();
right.preorder();
}
public void postorder(){
if(left !=null)
left.postorder();
right.postorder();
System.out.println(value);
}
}