EdgeWeightedGraph Class |
The EdgeWeightedGraph class represents an edge-weighted graph of vertices named 0 through V - 1, where each undirected edge is of type and has a real-valued weight. It supports the following two primary operations: add an edge to the graph, iterate over all of the edges incident to a 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 @link{Bag} objects. All operations take constant time (in the worst case) except iterating over the edges incident to a given vertex, which takes time proportional to the number of such edges.
Namespace: Algs4Net
public class EdgeWeightedGraph
The EdgeWeightedGraph type exposes the following members.
Name | Description | |
---|---|---|
![]() | EdgeWeightedGraph(Int32) |
Initializes an empty edge-weighted graph with V vertices and 0 edges. |
![]() | EdgeWeightedGraph(TextInput) |
Initializes an edge-weighted graph from an 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. |
![]() | EdgeWeightedGraph(Int32, Int32) |
Initializes a random edge-weighted graph with V vertices and E edges. |
Name | Description | |
---|---|---|
![]() | E |
Returns the number of edges in this edge-weighted graph. |
![]() | V |
Returns the number of vertices in this edge-weighted graph. |
Name | Description | |
---|---|---|
![]() | AddEdge |
Adds the undirected edge e to this edge-weighted graph. |
![]() | Adj |
Returns the edges incident on vertex v. |
![]() | Degree |
Returns the degree of vertex v. |
![]() | Edges |
Returns all edges in this edge-weighted graph.
To iterate over the edges in this edge-weighted graph, use foreach notation:
foreach (Edge e in G.Edges()). |
![]() ![]() | MainTest | Demo test the EdgeWeightedGraph data type. |
![]() | ToString |
Returns a string representation of the edge-weighted graph.
This method takes time proportional to E + V. (Overrides ObjectToString.) |
This class is a C# port from the original Java class EdgeWeightedGraph implementation by Robert Sedgewick and Kevin Wayne.