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

Inheritance Hierarchy
SystemObject
  Algs4NetDigraph

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

The Digraph type exposes the following members.

Constructors
  NameDescription
Public methodDigraph(Int32)
Initializes an empty digraph with V vertices.
Public methodDigraph(Digraph)
Initializes a new digraph that is a deep copy of the specified digraph.
Public methodDigraph(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.
Top
Properties
  NameDescription
Public propertyE
Returns the number of edges in this digraph.
Public propertyV
Returns the number of vertices in this digraph.
Top
Methods
  NameDescription
Public methodAddEdge(Edge)
Adds the undirected edge to this graph.
Public methodAddEdge(Int32, Int32)
Adds the directed edge v->w to this digraph.
Public methodAdj
Returns the vertices adjacent from vertex v in this digraph.
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 Digraph data type.
Public methodOutdegree
Returns the number of directed edges incident from vertex v. This is known as the Outdegree of vertex v.
Public methodReverse
Returns the reverse of the digraph.
Public methodToString
Returns a string representation of the graph.
(Overrides ObjectToString.)
Top
Remarks

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.

See Also