@@ -0,0 +1,948 @@
+/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; %7D%0A * %7D%0A */%0A %0Aimport java.util.Stack;%0A%0Apublic class BSTIterator %7B%0A    private Stack%3CTreeNode%3E stack;%0A    private TreeNode curt;%0A%0A    public BSTIterator(TreeNode root) %7B%0A        stack = new Stack%3CTreeNode%3E();%0A        curt = root;%0A    %7D%0A%0A    /** @return whether we have a next smallest number */%0A    public boolean hasNext() %7B%0A        return (curt != null) %7C%7C (!stack.empty());%0A    %7D%0A%0A    /** @return the next smallest number */%0A    public int next() %7B%0A        while(curt != null) %7B%0A            stack.push(curt);%0A            curt = curt.left;%0A        %7D%0A        TreeNode res = stack.pop();%0A        curt = res.right;%0A        %0A        return res.val;%0A    %7D%0A%7D%0A%0A/**%0A * Your BSTIterator will be called like this:%0A * BSTIterator i = new BSTIterator(root);%0A * while (i.hasNext()) v%5Bf()%5D = i.next();%0A */%0A

Create BinSearchTreeIterator_001.java