Cover Data Structures and Algorithms with Object-Oriented Design Patterns in Java
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.

   program49289
Program: GraphAsLists fields and constructor.

Each instance of the GraphAsLists class represents an undirected graph, say tex2html_wrap_inline69997. The set of vertices, tex2html_wrap_inline69999, is represented using the vertex array inherited from the AbstractGraph base class. The set of edges, tex2html_wrap_inline70005, is represented using the adjacencyList field, which is an array of linked lists. The tex2html_wrap_inline57340 linked list, adjacencyList[i], represents the set tex2html_wrap_inline70525 which is the set of edges emanating from vertex tex2html_wrap_inline70163. 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 © 1998 by Bruno R. Preiss, P.Eng. All rights reserved.