Tuesday, October 1, 2013

tree traversal iteratively


  • In order: 
    • using stack
  • Pre order: 
    • only check stack.top() 的right child, not left child. 

  • Post order:  3 possibilities when doing traversal 
    • traversing up the tree from the right
    • traversing up the tree from the left
    • traversing down the tree
    • Can be used to get the max depth of a tree, without changing the tree structure