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

        Stack<TreeNode> stack = new Stack<TreeNode>();
        stack.push(root);
        // Use isLeftVisited to mark if cur's left child is already visited
        boolean isLeftVisited = false;
        while (!stack.isEmpty()) {
            TreeNode cur = stack.peek();
            if (cur.left == null || isLeftVisited) {
                result.add(cur.val);
                stack.pop();
                isLeftVisited = true;
                if (cur.right != null) {
                    stack.push(cur.right);
                    isLeftVisited = false;
                }
            } else {
                stack.push(cur.left);
                isLeftVisited = false;
            }
        }

        return result;

    }