public static List<Integer> preorderTraversalnonrecursive (TreeNode root) {
        ArrayList<Integer> arrlst = new ArrayList<Integer>();
        if (root == null) return arrlst;
        Stack<TreeNode> stk = new Stack<TreeNode>();
        stk.push(root);
        while (stk.isEmpty() == false) {
            TreeNode temp = stk.pop();
            arrlst.add(temp.val);
            if (temp.right != null) stk.push(temp.right);
            if (temp.left != null) stk.push(temp.left);
        }
        return arrlst;
    }