Package algs44
Class EdgeWeightedDigraph
java.lang.Object
algs44.EdgeWeightedDigraph
The
EdgeWeightedDigraph class represents an directed graph of vertices
named 0 through V-1, where each edge has a real-valued weight.
It supports the following operations: add an edge to the graph,
iterate over all of edges leaving a vertex.
Parallel edges and self-loops are permitted.
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionEdgeWeightedDigraph(int V) Create an empty edge-weighted digraph with V vertices.EdgeWeightedDigraph(int V, int E) Create a random edge-weighted graph with V vertices and E edges with no parallel edges or self loops.EdgeWeightedDigraph(int V, int E, boolean allowParallelEdgesAndSelfLoops) Create a random edge-weighted graph with V vertices and E edges.Copy constructor.Create an edge-weighted digraph from input stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the edge e to this digraph.adj(int v) Return the edges leaving vertex v as an Iterable.intE()Return the number of edges in this digraph.edges()Return all edges in this graph as an Iterable.static voidTest client.intoutdegree(int v) Return number of edges leaving v.voidtoGraphviz(String filename) Save a graphviz representation of the graph.toString()Return a string representation of this graph.intV()Return the number of vertices in this digraph.
-
Field Details
-
V
-
E
-
adj
-
-
Constructor Details
-
EdgeWeightedDigraph
Create an empty edge-weighted digraph with V vertices. -
EdgeWeightedDigraph
Create a random edge-weighted graph with V vertices and E edges with no parallel edges or self loops. The expected running time is proportional to V + E. -
EdgeWeightedDigraph
Create a random edge-weighted graph with V vertices and E edges. The expected running time is proportional to V + E. -
EdgeWeightedDigraph
Create an edge-weighted digraph from input stream. -
EdgeWeightedDigraph
Copy constructor.
-
-
Method Details
-
V
Return the number of vertices in this digraph. -
E
Return the number of edges in this digraph. -
addEdge
Add the edge e to this digraph. -
adj
Return the edges leaving vertex v as an Iterable. To iterate over the edges leaving vertex v, use foreach notation:for (DirectedEdge e : graph.adj(v)). -
edges
Return all edges in this graph as an Iterable. To iterate over the edges, use foreach notation:for (DirectedEdge e : graph.edges()). -
outdegree
Return number of edges leaving v. -
toString
Return a string representation of this graph. -
toGraphviz
Save a graphviz representation of the graph. See graphviz.org. -
main
Test client.
-