I\'m doing a small Java work on Binary Search Tree but when I\'m implementing the recursive insert of a node into the tree and display it, I don\'t get anything. I\'ve been on i
Your left, right element of the BSTNodes are null. You need to create them before inserting into it. Otherwise they create an empty hanging BSTNode() and insert it, without connecting to the rest of the tree.
You can change the lines,
if ( elem.compareTo( root.element ) < 0 ) {
insertR( root.left, elem );
} else {
insertR( root.right, elem );
}
to
if ( elem.compareTo( root.element ) < 0 ) {
if ( root.left == null )
root.left = new BSTNode( elem );
else
insertR( root.left, elem );
} else {
if ( root.right == null )
root.right = new BSTNode( elem );
else
insertR( root.right, elem );
}