In Java, write everything from scratch (no IDE scaffolding):
-
Define a generic Iterator
<T>
interface with hasNext() and next().
-
Implement ArrayIterator
<T>
over a fixed array.
-
Implement PeekingIterator
<T>
that wraps any Iterator
<T>
and adds peek() without advancing.
-
Provide minimal unit tests that compile and run, covering empty input, single element, multiple elements, and calling next() when no elements remain. Analyze time/space complexity and edge cases.