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);
			}
			
		}

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

You can mark it as solved if it's solved.

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

if(value !=null)

value is an int, and can never be null. Only Object references can be null.

ok thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.