public class BSTIterator {

LinkedList<Integer> queue;

```
public BSTIterator(TreeNode root) {
queue = new LinkedList<Integer>();
inOrder(root);
}
/** @return whether we have a next smallest number */
public boolean hasNext() {
return !queue.isEmpty();
}
/** @return the next smallest number */
public int next() {
if(hasNext()) return queue.poll();
throw new NullPointerException();
}
public void inOrder(TreeNode root){
if(root==null) return;
inOrder(root.left);
queue.offer(root.val);
inOrder(root.right);
}
```

}