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

Implementing Vertices

What exactly is a vertex? The answer to this question depends on the application. At the very minimum, every vertex in a graph must be distinguishable from every other vertex in that graph. We can do this by numbering consecutively the vertices of a graph.

Program gif defines the concrete class Vertex. Since we intend to insert instances of this class into containers, the Vertex class is derived from the Object base class. The Vertex class declares a single member the single member variable number. Each vertex inserted into a graph is required to have a different number.

   program49684
Program: Vertex Class Definition

A single Vertex constructor is declared. This constructor takes as its lone argument the number that is to be assigned to the vertex. In addition, the cast-to-Number member function (operator Number) is also declared. This allows the programmer to use a vertex wherever an integer is expected. The cast returns the value of the number member variable.


next up previous contents index

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