Digraph Class |
The Digraph class represents a directed graph of vertices named 0 through V - 1. It supports the following two primary operations: add an edge to the digraph, iterate over all of the vertices adjacent from a given vertex. Parallel edges and self-loops are permitted.
This implementation uses an adjacency-lists representation, which is a vertex-indexed array of objects. All operations take constant time (in the worst case) except iterating over the vertices adjacent from a given vertex, which takes time proportional to the number of such vertices.
Namespace: Algs4Net
public class Digraph
The Digraph type exposes the following members.
Name | Description | |
---|---|---|
![]() | Digraph(Int32) | Initializes an empty digraph with V vertices. |
![]() | Digraph(Digraph) |
Initializes a new digraph that is a deep copy of the specified digraph. |
![]() | Digraph(TextInput) |
Initializes a digraph from the text input stream.
The format is the number of vertices V,
followed by the number of edges E,
followed by E pairs of vertices, with each entry separated by whitespace. |
Name | Description | |
---|---|---|
![]() | E |
Returns the number of edges in this digraph. |
![]() | V |
Returns the number of vertices in this digraph. |
Name | Description | |
---|---|---|
![]() | AddEdge(Edge) |
Adds the undirected edge to this graph. |
![]() | AddEdge(Int32, Int32) |
Adds the directed edge v->w to this digraph. |
![]() | Adj |
Returns the vertices adjacent from vertex v in this digraph. |
![]() | Indegree |
Returns the number of directed edges incident to vertex v.
This is known as the Indegree of vertex v. |
![]() ![]() | MainTest |
Demo test the Digraph data type. |
![]() | Outdegree |
Returns the number of directed edges incident from vertex v.
This is known as the Outdegree of vertex v. |
![]() | Reverse |
Returns the reverse of the digraph. |
![]() | ToString |
Returns a string representation of the graph. (Overrides ObjectToString.) |
For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
This class is a C# port from the original Java class Digraph implementation by the respective authors.