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

Edges

An edge in a directed graph is an ordered pair of vertices; an edge in an undirected graph is a set of two vertices. Because of the similarity of these concepts, we use the same class for both--the context in which an edge is used determines whether it is directed or undirected.

Program gif defines the Edge interface. Since we intend to edges into containers, the Edge interface extends the Comparable interface defined in Program gif.

   program49062
Program: Edge interface.

An edge connects two vertices, tex2html_wrap_inline70471 and tex2html_wrap_inline70191. The methods getV0 and getV1 return these vertices. The isDirected method is a boolean-valued method that returns true if the edge is directed. When an Edge is directed, it represents tex2html_wrap_inline70475. That is, tex2html_wrap_inline70191 is the head and tex2html_wrap_inline70471 is the tail. Alternatively, when an Edge is undirected, it represents tex2html_wrap_inline70481.

For every instance e of a class that implements the Edge interface, the getMate method satisfies the following identities:

gather49089

Therefore, if we know that a vertex v is one of the vertices of e, then we can find the other vertex by calling e.getMate(v).


next up previous contents index

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