Question: An alternative to providing a ListIterator is to provide a method with signature Iterator reverseIterator( ) that returns an Iterator, initialized to the last item,

An alternative to providing a ListIterator is to provide a method with signature
Iterator reverseIterator( )
that returns an Iterator, initialized to the last item, and for which next and hasNext are implemented to be consistent with the iterator advancing toward the front of the list, rather than the back. Then you could print a MyArrayList L in reverse by using the code
Iterator<AnyType> ritr = L.reverseIterator( ); while( ritr.hasNext( ) ) System.out.printin( ritr.next( ) );
Implement an ArrayListReverseIterator class, with this logic, and have reverseIterator return a newly constructed ArrayListReverseIterator.

Iterator ritr = L.reverseIterator( ); while( ritr.hasNext( ) ) System.out.printin( ritr.next( ) );

Step by Step Solution

3.43 Rating (162 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Iterator reverseIterator return new ArrayListReverseIterator private class ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

1486-C-S-A(291).docx

120 KBs Word File

Students Have Also Explored These Related Algorithms Questions!