public void iterative(List<Integer> res, TreeNode head) {
        Stack<TreeNode> stack = new Stack<TreeNode>();
        TreeNode cur = head;
        while (!stack.isEmpty() || cur != null) {
            while (cur != null) {
                stack.push(cur);
                cur = cur.left;
            }
            cur = stack.pop();
            res.add(cur.val);
            cur = cur.right;
        }
    }