0

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);
			}
			
		}
3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by chinee
0

the erroe is the if statement it is saying that the operator != is undefined for the argument type(s)int,null

0

it is not solve that is just the error stated but why is it only line 40 giving the error.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.