@@ -0,0 +1,995 @@
+/**%0A * Definition for a binary tree node.%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 */%0Aclass BSTIterator %7B%0A    %0A    private Queue%3CInteger%3E queue;%0A%0A    public BSTIterator(TreeNode root) %7B%0A        queue = new LinkedList%3C%3E();%0A        inorderTraversal(root);%0A    %7D%0A    %0A    private void inorderTraversal(TreeNode root) %7B%0A        if (root != null) %7B%0A            inorderTraversal(root.left);%0A            queue.offer(root.val);%0A            inorderTraversal(root.right);%0A        %7D%0A    %7D%0A    %0A    /** @return the next smallest number */%0A    public int next() %7B%0A        return queue.poll();%0A    %7D%0A    %0A    /** @return whether we have a next smallest number */%0A    public boolean hasNext() %7B%0A        return !queue.isEmpty();%0A    %7D%0A%7D%0A%0A/**%0A * Your BSTIterator object will be instantiated and called as such:%0A * BSTIterator obj = new BSTIterator(root);%0A * int param_1 = obj.next();%0A * boolean param_2 = obj.hasNext();%0A */

add no.173