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

Using Adjacency Matrices

The GraphAsMatrix is introduced in Program gif. The GraphAsMatrix class extends the AbstractGraph class introduced in Program gif.

   program49469
Program: GraphAsMatrix fields and constructor.

Each instance of the GraphAsMatrix class represents an undirected graph, say tex2html_wrap_inline70252. The set of vertices, tex2html_wrap_inline70254, is represented using the vertex array inherited from the AbstractGraph base class. Each vertex is represented by a separate GraphVertex instance.

Similarly, The set of edges, tex2html_wrap_inline70260, is represented using the matrix field which is a two-dimensional array of Edges. Each edge is represented by a separate GraphEdge instance.

The GraphAsMatrix constructor takes a single argument of type int that specifies the maximum number of vertices that the graph may contain. This quantity specifies the length of the array of vertices and the dimensions of the adjacency matrix. The implementation of the GraphAsMatrix class is left as programming project for the reader (Project gif).


next up previous contents index

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