This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
| ''' | |
| Interview hack: Memorize preorder/inorder/postorder tree ITERATORS (no recursion) and their reverses. | |
| It simplifies a disproportionate number of questions to simple for loops (see below). | |
| I consider the implementations below the simplest way to memorize the iterative tree traversal algorithms, | |
| because they are so similar to each other, and to their respective recursive versions. | |
| Notes: | |
| - We only visit a node after we have expanded its children (i.e. added them to the stack) in the desired order. | |
| - `x is curr` does the expanded flagging for us, because we always expand the current node. |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer