intnext(){ auto root = stk.top(); stk.pop(); int val = root->val; root = root->right; while(root){ stk.push(root); root = root->left; } return val; }
boolhasNext(){ return stk.size(); } };
/** * Your BSTIterator object will be instantiated and called as such: * BSTIterator* obj = new BSTIterator(root); * int param_1 = obj->next(); * bool param_2 = obj->hasNext(); */