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