class BSTIterator {

public:

BSTIterator(TreeNode *root) {

```
inorder(root);
}
/** @return whether we have a next smallest number */
bool hasNext() {
return _q.size()>0;
}
/** @return the next smallest number */
int next() {
int a=_q.front();
_q.pop();
return a;
}
void inorder(TreeNode* node)
{
if(node == NULL)return;
inorder(node->left);
_q.push(node->val);
inorder(node->right);
}
queue<int> _q;
```

};