Click or drag to resize
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.

Inheritance Hierarchy
SystemObject
  Algs4NetEdgeWeightedDigraph

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class EdgeWeightedDigraph

The EdgeWeightedDigraph type exposes the following members.

Constructors
  NameDescription
Public methodEdgeWeightedDigraph(Int32)
Initializes an empty edge-weighted digraph with V vertices and 0 edges.
Public methodEdgeWeightedDigraph(EdgeWeightedDigraph)
Initializes a new edge-weighted digraph that is a deep copy of G.
Public methodEdgeWeightedDigraph(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.
Public methodEdgeWeightedDigraph(Int32, Int32)
Initializes a random edge-weighted digraph with V vertices and E edges.
Top
Properties
  NameDescription
Public propertyE
Returns the number of edges in this edge-weighted digraph.
Public propertyV
Returns the number of vertices in this edge-weighted digraph.
Top
Methods
  NameDescription
Public methodAddEdge
Adds the directed edge e to this edge-weighted digraph.
Public methodAdj
Returns the directed edges incident from vertex v.
Public methodEdges
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()).
Public methodIndegree
Returns the number of directed edges incident to vertex v. This is known as the Indegree of vertex v.
Public methodStatic memberMainTest
Demo test the EdgeWeightedDigraph data type.
Public methodOutdegree
Returns the number of directed edges incident from vertex v. This is known as the Outdegree of vertex v.
Public methodToString
Returns a string representation of this edge-weighted digraph.
(Overrides ObjectToString.)
Top
Remarks

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.

See Also