ICS 211 Homework 8

Iterator

0. Goals and Overview

The goal of this assignment is to understand how iterators are implemented and used.

1. Iterator (60%)

Your HW8Iterator class must implement the standard Iterator interface.

In addition to implementing the Iterator interface, your HW8Iterator must provide the hasPrevious(), previous(), nextIndex(), and previousIndex() methods of the ListIterator interface.

The constructor for your iterator must take as parameter a value of type List. Of this parameter (which you should save as an instance variable) your entire iterator is only allowed to call the methods get(int index) and size(). No other calls to outside methods (i.e. methods not defined within the iterator) are allowed in the entire iterator. For example, you are not even allowed to call System.out.println, and you certainly are not allowed to call the iterator() or toArray methods of the constructor's parameter, not even implicitly with a foreach loop.

Your unit test does not have these restrictions, in other words it may call any method from any standard library.

2. Testing (20%)

Create a unit test HW8Test class where the main method thoroughly evaluates your iterator. The quality of your test contributes to your grade for this assignment.

3. Analysis (20%)

Give a clear analysis of the worst-case, best-case, and average-case execution time for your iterator's constructor, and the hasNext() and next() methods. You may have different results depending on the kind of list that is provided to the constructor, so be sure your answers include the runtime when the list is a (a) singly-linked list, (b) doubly-linked list, and (c) array list.

Turning in the Assignment

Once you are done, find your src directory and navigate to edu.ics211.h08, then turn the .java files and your analysis.txt into Laulima directly, without zipping or archiving.