Inorder  left --> root -->right
public ArrayList<Integer> inorderTra(TreeNode root){
   ArrayList<Integer> res = new ArrayList<Integer>();
Stack<TreeNode> stk = new Stack<TreeNode>();

while (!stk.isEmpty() || root != null) {
     if (root != null) {
        stk.push(root);
        root = root.left;
    }
    else { TreeNode tmp = stk.pop();
           res.add(tmp.val);
           root = tmp.right;
       }    
  }
   return res;
}

results matching ""

    No results matching ""