# Preorder, Inorder, and Postorder Iteratively Summarization

• @nick46 What do you mean by topological dependency? Could you give me a simple example?

• @ofLucas Brilliant, the only one that achieved postorder I have seen so far without the aid of `prev` pointer (aside from Morris Traversal).

• ``````class Solution {
public List<Integer> postorderTraversal(TreeNode root) {
Stack<TreeNode> stack = new Stack<>();
List<Integer> res = new ArrayList<>();
TreeNode iter = root;
while(iter != null || !stack.isEmpty()) {
while(iter != null) {
if(iter.right != null) stack.push(iter.right);
stack.push(iter);
iter = iter.left;
}
//
iter = stack.pop();
if(iter.right != null && !stack.isEmpty() &&  iter.right == stack.peek()) {
TreeNode temp = stack.pop();
stack.push(iter);
iter = temp;
}
else {
iter = null;
}
}
return res;
}
}
``````

• Here is my idea, using recursive + iterative + morris
leetcode 145

• @monkeykingyan Morris is your idea?

• @jedihy Not my idea, but you can use Morris to solve all the tree traversal problems.

• @yavinci
Postorder traversal is left-right symmetric to the preorder traversal.
You can find a much shorter solution here.

``````vector<int> postorderTraversal(TreeNode* root) {
vector<int> nums;
stack<TreeNode* > stnode;
while (root || !stnode.empty()) {
if (!root) {
root = stnode.top();
stnode.pop();
}
nums.push_back(root->val);
if (root->left) stnode.push(root->left);
root = root->right;
}
return vector<int>(nums.rbegin(), nums.rend())
}
``````

https://discuss.leetcode.com/topic/104897/the-simplest-iterative-morris-solutions-postorder-is-symmetric-to-the-preorder

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.