Java implements traversal of binary tree