12/38
Part 3 of 7 · Your own stackLearn and do

Your stack takes the children right to left, and recursion left to right

Both walks go as deep as they can, in a different order.

Visit order: recursion, then your stack
Portugal
1, 1
Lisbon District
2, 4
Lisbon
3, 7
Sintra
4, 6
Cascais
5, 5
Porto District
6, 2
Porto
7, 3

Both go as deep as they can before they back up. They differ in which child goes first. The last child pushed is the first popped, so your stack takes the children right to left.

Predict

Which one change makes your stack visit a tree in recursion's order?

Pick an answer above to see the rest