(LeetCode) T94. Binary Tree Inorder Traversal

Problem:Given a binary tree, return the inorder traversal of its nodes' values.

(LeetCode) T94. Binary Tree Inorder Traversal

Solve:

(LeetCode) T94. Binary Tree Inorder Traversal

Thought:I solve it by using recursive solution.It's so easy to do it with its definition.

So there is a tip like this.

Follow up: Recursive solution is trivial, could you do it iteratively?

18.5.16 修改

非递归方法实现:

Solve:

(LeetCode) T94. Binary Tree Inorder Traversal

Thought :不断将当前的左结点存储(压栈),直到到达最左的结点,打印该节点,然后访问该节点的右子树,访问完后退回储存的上一节点。

即按照左-中-右的顺序(中序遍历)