next up previous contents index
Next: Dictionary Pattern Up: General Programming Patterns and Previous: CLAM Pattern   Contents   Start


List Pattern

All programming languages provide a feature to collect data in some sort of container one way or another.[*] In A++ collections are implemented as lists and dictionaries.

Lists are implemented as linked lists of pairs. A pair is composed of a head and a tail. The head points to a data item and the tail points to the next pair in the list.

img57.gif\includegraphics{img/paar.eps}
The tail in the last pair of the list points to a special element called `nil' or `null'. It is the programmer's responsibility to make sure that a list is terminated with the element `nil'.
img58.gif\includegraphics{img/liste2.eps}
img59.gif\includegraphics{img/nil.eps}

In order to work with pairs and lists the following abstractions are needed as a minimum:

The section lists:basics presents these abstractions and many more that can be used in the list context.

A head of a pair may be anything, i.e also a reference of another pair. This way it is possible to construct lists of lists, providing the power to build a tree or any other network structure.

img60.gif\includegraphics{img/lili.eps}


next up previous contents index
Next: Dictionary Pattern Up: General Programming Patterns and Previous: CLAM Pattern   Contents   Start

Georg P. Loczewski 2004-03-05


Impressum und Datenschutz