/** * A linked list iterator that does not support remove * @author Edo Biagioni * @lecture ICS 211 Feb 3 (or later) * @date February 1, 2011 */ private class LinkedListIterator implements java.util.Iterator<E> { private LinkedNode<E> current; private LinkedListIterator() { current = head; // from the enclosing class -- // ListIterator cannot be a static class } public boolean hasNext() { return (current != null); } public E next() { if (hasNext()) { E result = current.item; current = current.next; // may be null return result; } // no next element throw new java.util.NoSuchElementException("linked list.next"); } public void remove() { throw new UnsupportedOperationException ("Linked list iterator remove not supported"); } }