Logo Data Structures and Algorithms with Object-Oriented Design Patterns in C++
next up previous contents index

Graph Traversals

These graph traversal functions are analogous to the Accept member function of the container class (see Section gif). Each of these functions takes a reference to a Visitor and performs a traversal. I.e., all the vertices of the graph are visited systematically. When a vertex is visited, the Visit function of the visitor is applied to that vertex.

DepthFirstTraversal and BreadthFirstTraversal
Both of these functions accept two arguments--a reference to a Visitor and a reference to a vertex. The vertex specifies the starting node for either a depth-first traversal or a breadth-first traversal of the graph.
TopologicalOrderTraversal
A topological sort is an ordering of the nodes of a directed graph. This traversal visits the nodes of a directed graph in the order specified by a topological sort. Therefore, it is a member function of the Digraph class.

The graph traversal algorithms are discussed in Section gif.


next up previous contents index

Bruno Copyright © 1997 by Bruno R. Preiss, P.Eng. All rights reserved.