SWE/CS 332 In Class Exercise Number 12
Tuesday October 10, 2017

Names:

Goal: Introduce students to understanding iteration from the perspective of abstract state.

Consider a two-way iterator:

public interface TwoWayIterator <E> {
	boolean hasNext();
	boolean hasPrevious();
	E next ();
	E previous ();
}
  1. Work out the behavior of such an iterator for the Poly 3 + 4x + 5x^3

  2. Is it necessary for the Poly to be part of the abstract state? (What do you need to consider to answer this question?)

  3. What is the abstract state of this iterator at each stage of the behavior in step 1?



  4. Repeat the prior 3 steps for an iterator with a remove method:
    public interface Iterator <E> {
    	boolean hasNext ();
    	E next ();
    	void remove();
    }
    
    • Is there a problem with using Poly as an example?

    • Does the List [cat, dog, mouse] work better?