public static ArrayList<Integer> inorderTraversal2(TreeNode root) {
    	ArrayList<Integer> list =new ArrayList<Integer>();
        if(root == null) return list;
        TreeNode prev = null;
        Stack<TreeNode> stack = new Stack<TreeNode>();
        stack.add(root);
        while(!stack.isEmpty()){
        	TreeNode cur = stack.peek();
        	if(prev == null || prev.left == cur || prev.right == cur){
        		if(cur.left != null) stack.push(cur.left);
        		else if(cur.right != null) stack.push(cur.right);
        	}else if(cur.left == prev){
        		if(cur.right != null) stack.push(cur.right);
        	}else{
        		list.add(stack.pop().val);
        	}
        	prev = cur;
        }
        return list;
    }