You are viewing a single comment's thread. Return to all comments →
The order is: 1. Recurse over the left subtree 2. Print the value of the node 3. Recurse over the right subtree
When looking at node 2, since the left subtree at node 2 is empty, step 1 at this node does nothing and so it goes directly to step 2.
Node 9 is actually at the bottom of the RIGHT branch from the perspective of node 2, so 2 gets printed before 9.
Swap Nodes
You are viewing a single comment's thread. Return to all comments →
The order is: 1. Recurse over the left subtree 2. Print the value of the node 3. Recurse over the right subtree
When looking at node 2, since the left subtree at node 2 is empty, step 1 at this node does nothing and so it goes directly to step 2.
Node 9 is actually at the bottom of the RIGHT branch from the perspective of node 2, so 2 gets printed before 9.