2
* Below is the interface for Iterator, which is already defined for you.3
* **DO NOT** modify the interface for Iterator.9
* Iterator(const vector<int>& nums);10
* Iterator(const Iterator& iter);12
* // Returns the next element in the iteration.15
* // Returns true if the iteration has more elements.16
* bool hasNext() const;20
class PeekingIterator : public Iterator {24
PeekingIterator(const vector<int> &nums) : Iterator(nums) {25
// Initialize any member here.26
// **DO NOT** save a copy of nums and manipulate it directly.27
// You should only use the Iterator interface methods.29
_hasNext = Iterator::hasNext();30
if (_hasNext) _nextVal = Iterator::next();33
// Returns the next element in the iteration without advancing the iterator.38
// hasNext() and next() should behave the same as in the Iterator interface.39
// Override them if needed.43
_hasNext = Iterator::hasNext();44
if (_hasNext) _nextVal = Iterator::next();48
bool hasNext() const {