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

        Stack<TreeNode> parentStack = new Stack<TreeNode>();
        TreeNode cur = root;
        while (!parentStack.isEmpty() || cur != null) {
            if (cur != null) {
                result.add(cur.val);
                parentStack.push(cur);
                cur = cur.left;
            } else {
                cur = parentStack.pop();
                cur = cur.right;
            }
        }
        return result;
    }