1 public class Solution { 2 public ArrayList<Integer> inorderTraversal(TreeNode root) { 3 ArrayList<Integer> res = new ArrayList<Integer> (); 4 Stack<TreeNode> stack = new Stack<TreeNode>(); 5 TreeNode cur = root; 6 while(!stack.isEmpty()||cur!=null){ 7 if(cur!=null){ 8 stack.push(cur); 9 cur = cur.left; 10 } 11 else{ 12 cur = stack.pop(); 13 res.add(cur.val); 14 cur = cur.right; 15 } 16 } 17 return res; 18 } 19 }
原文:http://www.cnblogs.com/krunning/p/3538796.html