rewrite inorder traversal using iterate