1
// Java Iterator interface reference:2
// https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html4
class PeekingIterator implements Iterator<Integer> {7
public PeekingIterator(Iterator<Integer> iterator) {8
// initialize any member here.9
q = new LinkedList<>();10
while (iterator.hasNext()) q.add(iterator.next());13
// Returns the next element in the iteration without advancing the iterator.14
public Integer peek() {18
// hasNext() and next() should behave the same as in the Iterator interface.19
// Override them if needed.21
public Integer next() {26
public boolean hasNext() {