I want to go through a binary tree recursive in the method public void inorder(). Afterwards I want to give out all the values which are in the binary tree. But in my case the recursive process does not work.Can somebody help?
I tried to do the recursive process with a static method but of course it is not working. I do not know how can I write the recursive process different from a static method recursive method. That is may problem. Can somebody help?
class BinaryNode {
private BinaryNode leftSon, rightSon;
private int value;
public BinaryNode(int v) {
value = v;
}
public boolean contains(int v) {
if ( ( leftSon != null) & ( rightSon != null) )
if ( v == value ) return true;
else
if ( v < value ) leftSon.contains( v ) ;
else rightSon.contains( v );
return false;
}
public void insert(int v) {
if ( v != value ) {
if ( v < value ) {
BinaryNode links = new BinaryNode( v );
}
} else {
BinaryNode rechts = new BinaryNode( v );
}
}
public void inorder() {
if ( leftSon != null ) { inorder( ) ; }
System.out.println( value );
if ( rightSon != null ) { inorder( ) ; }
System.out.println( value );
}
}