public ArrayList<Integer> preorderTraversalWithIterative(TreeNode root) {
            ArrayList<Integer> preorder = new ArrayList<Integer>();
            ArrayDeque<TreeNode> stack = new ArrayDeque<TreeNode>();
            if (root != null) {
                stack.offerLast(root);
                while (!stack.isEmpty()) {
                    TreeNode p = stack.removeLast();
                    while (p != null) {
                        preorder.add(p.val);
                        if (p.right != null) {
                            stack.offerLast(p.right);
                        }
                        p = p.left;
                    }
                }
            }
            return preorder;
        }