• 39.0%

https://leetcode.com/problems/binary-tree-postorder-traversal/#/description

Given a binary tree, return the postorder traversal of its nodes’ values.

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

##### 方法一：

Recursive solution

##### 方法二：

v.insert(v.begin(), val);

##### 方法三：

Iterative solution using stack — O(n) time and O(n) space;

Dec 10th, 2017

##### 方法四：

https://discuss.leetcode.com/topic/14473/0-ms-clear-c-solutions-iterative-recursive-morris-traversal-3-different-solutions

Morris traversal

Morris traversal:

https://discuss.leetcode.com/topic/30632/preorder-inorder-and-postorder-iteratively-summarization

Preorder, Inorder, and Postorder Iteratively Summarization

Here I summarize the iterative implementation for preorder, inorder, and postorder traverse.

PRE ORDER TRAVERSE

IN ORDER TRAVERSE

POST ORDER TRAVERSE

0ms, 24.98%, July 14th, 2016

https://discuss.leetcode.com/topic/2919/my-accepted-code-with-explaination-does-anyone-have-a-better-idea

My Accepted code with explaination. Does anyone have a better idea?

pre-order traversal is root-left-right, and post order is left-right-root. modify the code for pre-order to make it root-right-left, and then reverse the output so that we can get left-right-root .

1. Create an empty stack, Push root node to the stack.
2. Do following while stack is not empty.

2.1. pop an item from the stack and print it.

2.2. push the left child of popped item to stack.

2.3. push the right child of popped item to stack.

3. reverse the ouput.

4ms, 0.62%, July 14th, 2016

https://discuss.leetcode.com/topic/7427/a-very-concise-solution

A very concise solution

i have saw lots of post in this discussion, but most of them are not concise, just share mine for your reference, writing a concise code is very important

https://discuss.leetcode.com/topic/14473/0-ms-clear-c-solutions-iterative-recursive-morris-traversal-3-different-solutions

0 ms Clear C++ solutions — iterative, recursive, Morris traversal (3 different solutions!)

Hi, this is a fundamental and yet classic problem. I share my three solutions here:

1. Iterative solution using stack — O(n) time and O(n) space;
2. Recursive solution — O(n) time and O(n) space (considering the spaces of function call stack);
3. Morris traversal — O(n) time and O(1) space!!!

Iterative solution using stack:

Recursive solution:

Morris traversal:

44ms, 81.02%, July 14th, 2016

https://discuss.leetcode.com/topic/17540/share-my-two-python-iterative-solutions-post-order-and-modified-preorder-then-reverse

Share my two Python iterative solutions, post-order and modified preorder then reverse

The first is by postorder using a flag to indicate whether the node has been visited or not.

The 2nd uses modified preorder (right subtree first). Then reverse the result.

https://discuss.leetcode.com/topic/2325/accepted-just-a-reversal-of-a-modified-pre-order-traversal

Accepted – Just a reversal of a modified Pre-order traversal

This is my accepted code. I found out that pre-order traversal is root-left-right, and post order is left-right-root. I modified the code for pre-order a little to make it root-right-left, and then reverse the output. I think others would have thought of it already, but anyways here’s my code…

https://discuss.leetcode.com/topic/34258/iterative-method-to-do-three-kinds-of-traversal-just-like-recursive-method-only-changing-one-line-code

Iterative method to do three kinds of traversal just like recursive method only changing one line code

For three different kinds of traversal, we only need to change the order of tuples in one line as we’ve done this in the recursive solution which is very decent and classical. Just put (0, p[1]) in different position!

For post-order traversal:

For in-order traversal:

For pre-order traversal:

https://discuss.leetcode.com/topic/44231/preorder-inorder-and-postorder-traversal-iterative-java-solution

Preorder, Inorder and Postorder Traversal Iterative Java Solution

Postorder traversal : Binary Tree Postorder Traversal

Preorder traversal : Binary Tree Preorder Traversal

Inorder traversal : Binary Tree Inorder Traversal