next up previous contents
Next: Data Accessors Up: Helper Types for Flexibly Previous: Helper Types for Flexibly

Iterators

Iterators are a powerful technique in object-oriented programming and one of the fundamental design patterns [35]. Roughly speaking, an iterator is a small, light-weight object, which is associated with a specific kind of linear sequence. An iterator can be used to access all items in a linear sequence step-by-step. In this section, different iterator classes are introduced for traversing the nodes and the edges of a graph, and for traversing all ingoing and/or outgoing edges of a single node. Iterators are an alternative to the iteration macros introduced in sect. Graphs.3.(i). For example, consider the following iteration pattern:
    node v;
    forall_nodes (n, G) { ... }
Using the class NodeIt introduced in sect. Node Iterators, this iteration can be re-written as follows:
    for (NodeIt it (G); it.valid(); ++it) { ... }
The crucial differences are:
next up previous contents
Next: Data Accessors Up: Helper Types for Flexibly Previous: Helper Types for Flexibly
LEDA research project
1998-10-02