next up previous
Next: Unordered lists Up: Strings Previous: Strings

Iterators

Most of the example should be obvious. The use of iterators requires some explanation. An iterator is an object that is used to iterate over all elements of some other object. The iterator hides the exact structure of this other object. It doesn't matter whether the other object has a list structure, a tree structure, an acyclic graph structure or something else: the iterator is always used in the same way. With the hush ADT's, an interator is created in the following manner:
iter<element-type> iterator-name = object-to-be-iterated-over ;
The element type reflects the type of elements the iterator will return: iterating over a `split' string will result in seperate strings, iterating over a list of integers will result in seperate integers, etc. The assignment from an object to an iterator tells the iterator over which object it should iterate. Each time the function operator() is called, it will return a pointer to the next element. When there is no next element, operator() will return a null-pointer (0 or NULL).



SE Praktikum
Tue Aug 13 13:18:42 MET DST 1996