public static List<Integer> traverseWithIterative1(TreeNode root) {
        List<Integer> result = new ArrayList<Integer>();

        if (root == null)
            return result;

        Stack<TreeNode> stack = new Stack<TreeNode>();
        TreeNode cur = root;
        TreeNode previsited = root;
        stack.push(root);
        while (!stack.isEmpty()) {
            cur = stack.peek();
            // In post-order, the root of a tree will be visited at last, and
            // root's children are the also roots of the child trees. So a root
            // and its children will be visited closely.
            if ((cur.left == null && cur.right == null)
            // notice that previsited may be null
                    || (previsited == cur.left || previsited == cur.right)) {
                result.add(cur.val);
                previsited = cur;
                stack.pop();
            } else {
                if (cur.right != null) {
                    stack.add(cur.right);
                }

                if (cur.left != null) {
                    stack.add(cur.left);
                }
            }
        }
        return result;
    }