/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res=new ArrayList(); ArrayDeque<TreeNode> stack=new ArrayDeque(); //双端队列的使用 TreeNode tmp=root; while(!stack.isEmpty() || tmp!=null){ //双判断 if(tmp!=null){ stack.push(tmp); tmp=tmp.left; } else{ tmp=stack.pop(); res.add(tmp.val); tmp=tmp.right; } } return res; } }