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

Using Adjacency Lists

Program gif introduces the GraphAsLists class. The GraphAsLists extends the AbstractGraph class introduced in Program gif. The GraphAsLists class represents the edges of a graph using adjacency lists.

   program49496
Program: GraphAsLists fields and constructor.

Each instance of the GraphAsLists 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. The set of edges, tex2html_wrap_inline70260, is represented using the adjacencyList field, which is an array of linked lists. The tex2html_wrap_inline57621 linked list, adjacencyList[i], represents the set tex2html_wrap_inline70780 which is the set of edges emanating from vertex tex2html_wrap_inline70418. The implementation uses the LinkedList class given in Section gif.

The GraphAsLists constructor takes a single argument of type int that specifies the maximum number of vertices that the graph may contain. This quantity specifies the lengths of the array of vertices and the array of adjacency lists. The implementation of the GraphAsLists 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.