Reputation: 345
I don't understand this method.
protected void inorder(TreeNode<E> root) {
if (root == null) return;
inorder(root.left);
System.out.print(root.element + " ");
inorder(root.right);
}
When current node
comes to last node in the tree and current.left become null, what then happened? current node
returns where? When that node is going to print?
Upvotes: 2
Views: 662
Reputation: 70929
If root.left
is null, the function call inorder(root.left);
will do nothing but return immediatley and then you will continue on with root and its right subtree.
Upvotes: 1