Make tree traversal iterative