import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.Queue; import java.util.Iterator; public class Example4 { // Complete this class private class PeekingIterator // ... { // Introduce instance variables ... public PeekingIterator(Iterator it) { throw new RuntimeException("not implemented"); } public boolean hasNext() { throw new RuntimeException("not implemented"); } public T next() { throw new RuntimeException("not implemented"); } public T peek() { throw new RuntimeException("not implemented"); } public void remove() { throw new RuntimeException("not implemented"); } } public static void main(String[] args) { Queue q = new Queue(); q.enqueue("hello"); q.enqueue("world"); q.enqueue("!"); // Two ways of iterating over the objects of q. Iterator iterator = new PeekingIterator(q.iterator()); StdOut.println(iterator); StdOut.println(iterator.hasNext()); StdOut.println(iterator.next()); StdOut.println(iterator.peek()); StdOut.println(iterator.peek()); StdOut.println(iterator.hasNext()); StdOut.println(iterator.next()); // foreach loop for(String x : new PeekingIterator(q.iterator())) { StdOut.println(x); } } }