Data Structures and Algorithms with Object-Oriented Design Patterns in C#
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. The Edge interface extends the IComparable interface.

   program49246
Program: Edge interface.

An edge connects two vertices, tex2html_wrap_inline70726 and tex2html_wrap_inline70446. The properties V0 and V1 provide get accessors that return these vertices. The IsDirected property is a bool-valued accessor that returns true if the edge is directed. When an Edge is directed, it represents tex2html_wrap_inline70730. That is, tex2html_wrap_inline70446 is the head and tex2html_wrap_inline70726 is the tail. Alternatively, when an Edge is undirected, it represents tex2html_wrap_inline70736.

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

gather49274

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.Mate(v).


next up previous contents index

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