Data Structures and Algorithms
with Object-Oriented Design Patterns in C# |
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 defines the Edge interface. The Edge interface extends the IComparable interface.
An edge connects two vertices, and . 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 . That is, is the head and is the tail. Alternatively, when an Edge is undirected, it represents .
For every instance e of a class that implements the Edge interface, the Mate property satisfies the following identities:
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).