No Recursion | Using a stack


#1
public class Solution {
public ArrayList<Integer> inorderTraversal(TreeNode A) {
    ArrayList <Integer> result = new ArrayList <> ();
    if (A==null)
        return result;
    Stack <TreeNode> stack = new Stack <>();
    TreeNode curr = A;
    while (curr!=null || stack.size()!=0){
        while (curr!=null){
            stack.push (curr);
            curr=curr.left;
        }
        curr=stack.pop();
        result.add(curr.val);
        curr=curr.right;
    }
    return result;
}

}