public ArrayList<Integer> postorderTraversalWithIterative(TreeNode root) {
            ArrayList<Integer> postorder = new ArrayList<Integer>();
            if (root == null) {
                return postorder;
            }
            ArrayDeque<TreeNode> stack = new ArrayDeque<TreeNode>();
            TreeNode pre = null;
            stack.offerLast(root);
            while (!stack.isEmpty()) {
                TreeNode p = stack.peekLast();
                if (pre == null || pre.left == p || pre.right == p) {
                    if (p.left != null) {
                        stack.offerLast(p.left);
                    } else if (p.right != null) {
                        stack.offerLast(p.right);
                    }
                } else if (p.left == pre) {
                    if (p.right != null) {
                        stack.offerLast(p.right);
                    }
                } else {
                    postorder.add(p.val);
                    stack.removeLast();
                }
                pre = p;
            }
            return postorder;
        }