31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13<br />

Graphs and Iterators<br />

13.1 Introduction<br />

13.1.1 Iterators<br />

Iterators are a powerful technique in object-oriented programming and one of the fundamental<br />

design patterns [39]. Roughly speaking, an iterator is a small, light-weight object,<br />

which is associated with a specific kind of linear sequence. An iterator can be used to<br />

access all items in a linear sequence step-by-step. In this section, different iterator classes<br />

are introduced for traversing the nodes and the edges of a graph, and for traversing all<br />

ingoing and/or outgoing edges of a single node.<br />

Iterators are an alternative to the iteration macros introduced in sect. 11.1.3.(i).<br />

example, consider the following iteration pattern:<br />

For<br />

node v;<br />

forall_nodes (n, G) { ... }<br />

Using the class NodeIt introduced in sect. 13.2, this iteration can be re-written as follows:<br />

for (NodeIt it (G); it.valid(); ++it) { ... }<br />

<strong>The</strong> crucial differences are:<br />

• Iterators provide an intuitive means of movement through the topology of a graph.<br />

367

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!