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

Data Structures for Dijkstra's Algorithm

The implementation of Dijkstra's algorithm described below uses the TableEntry structure declared in Program gif. Each TableEntry instance has three fields, known, distance and predecessor, which correspond to the variables tex2html_wrap_inline72349, tex2html_wrap_inline72351 and tex2html_wrap_inline72353, respectively.

   program52055
Program: Data Structures for Dijkstra's Algorithm

In each pass of its operation, Dijkstra's algorithm selects from the set of vertices for which the shortest-path is not yet known the one with the smallest tentative distance. Therefore, we use a priority queue to represent this set of vertices.

The priority assigned to a vertex is its tentative distance. The class Assoc defined in Program gif is used to associate of a priority with a given object instance. The Assoc class is derived from the Association class given in Section gif. Notice that the Assoc constructor calls RescindOwnership to prevent the destructor from deleting the associated object instance.


next up previous contents index

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