600.226 Data Structures (Spring 2004 - Prof. Eisner)

Hint 2 for sorted iterators in Homework 4

You will probably want to write a method to find the next position, something like protected Position findNextPosition(Position old), where old is the position that was just returned by the iterator.

The simplest implementation is for findNextPosition to scan the whole list from left to right each time it is called, looking for the "best eligible position." A position is eligible if it has not been returned yet by the iterator. And among the new positions, some are better than others (should be returned sooner), because they have smaller elements or because they are earlier in the sequence.

So here are the four things you have to figure out:

If you get really stuck, here are some more hints about how to scan the list. But try hard to figure it out yourself first!


Jason Eisner - jason@cs.jhu.edu - $Date: 2004/02/18 07:19:00 $