1h

The order of in-order traversal is left - right - center

recursion

It’s very easy with recursion

var postorderTraversal = function(root) {
    var res = []
    if (!root)
    return res
    var travel = function (node) {
        node.left && travel(node.left)
        node.right && travel(node.right)
        res.push(node.val)
    }
    travel(root)
    return res
};
```Iteration

1. Push the root node onto the stack.
1. Determine whether a node can be popped. If so, record itself as the node that was popped and pop it.
1. If a node cannot be popped, push the right and left nodes onto the stack.
1. Repeat step 2.

```javascript
var postorderTraversal = function(root) {
    var stack = [root]
    var res = []
    if (!root) {
        return res
    }
    var pre = root    while(stack.length) {
        var node = stack[stack.length - 1]
        // When the left/right node of a node is the last node to be output, it means that both the left and right nodes have been output (because the root node is at the end of the post-order traversal) if ( (!node.left && !node.right) || (node.left === pre || node.right === pre)) {
             // Only when there is no left or right node, or both left and right nodes have been output, can node = stack.pop() be output.
            pre = node
            res.push(node.val)
        } else {
            if (node.right) {
                stack.push(node.right)
            }
            if(node.left) {
                stack.push(node.left)
            }
        }
    }
    return res
};
```Summarize

Although I have completed the forward, in-order, and post-order traversal of a binary tree, I have a feeling that I will forget it soon, especially the in-order and post-order traversal. I have not found any similarities between the two, so I will make a summary later.

1h

The order of in-order traversal is left - right - center

recursion

It's very easy with recursion

```javascript
var postorderTraversal = function(root) {
    var res = []
    if (!root)
    return res
    var travel = function (node) {
        node.left && travel(node.left)
        node.right && travel(node.right)
        res.push(node.val)
    }
    travel(root)
    return res
};
```Iteration

1. Push the root node onto the stack.
1. Determine whether a node can be popped. If so, record itself as the node that was popped and pop it.
1. If a node cannot be popped, push the right and left nodes onto the stack.
1. Repeat step 2.

```javascript
var postorderTraversal = function(root) {
    var stack = [root]
    var res = []
    if (!root) {
        return res
    }
    var pre = root    while(stack.length) {
        var node = stack[stack.length - 1]
        // When the left/right node of a node is the last node to be output, it means that both the left and right nodes have been output (because the root node is at the end of the post-order traversal) if ( (!node.left && !node.right) || (node.left === pre || node.right === pre)) {
             // Only when there is no left or right node, or both left and right nodes have been output, can node = stack.pop() be output.
            pre = node
            res.push(node.val)
        } else {
            if (node.right) {
                stack.push(node.right)
            }
            if(node.left) {
                stack.push(node.left)
            }
        }
    }
    return res
};
```Summarize

Although I've completed the forward, in-order, and post-order traversals of a binary tree, I have a feeling I'll soon forget them. This is especially true for the in-order and post-order traversals. I haven't found any similarities between them, so I'll summarize them later.