Untitled
class BSTIterator { //BASED ON ITERATIVE INORDER TRAVERSAL public: stack<TreeNode*> s; TreeNode* root; BSTIterator(TreeNode* roo) { //stack<TreeNode*> s; root=roo; pushf(root); } void pushf(TreeNode* node){ while(node!=NULL){ s.push(node); node=node->left; } } int next() { TreeNode* top=s.top(); s.pop(); pushf(top->right); return top->val; } bool hasNext() { return !(s.empty()); } };