The following loop:
while (n != null) {
inOrder(n.lchild);
System.out.println(n);
inOrder(n.rchild);
}
will run forever if n == null
. And will keep on calling the recursive method on each iteration. Perhaps, you should change it to:
if (n != null) {
inOrder(n.lchild);
System.out.println(n);
inOrder(n.rchild);
}