March 2005
Intermediate to advanced
600 pages
14h
English
CHAPTER 4 ITERATORS
An iterator is an object interface to a list.
The object’s member data consists of the list and some state information marking a “current position” in the list. The iterator supports one method, which we will call NEXTVAL. The NEXTVAL method returns the list element at the current position and updates the current position so that the next time NEXTVAL is called, the next list element will be returned.
Why would anyone want an object interface to a list? Why not just use a list? There are several reasons. The simplest is that the list might be enormous, so large that you do not want to have it in memory all at once. It is often possible to design iterators to generate list items as they’re requested, so that ...