Package algs43
Class EdgeWeightedGraph
java.lang.Object
algs43.EdgeWeightedGraph
The
EdgeWeightedGraph class represents an undirected 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,
in the graph, iterate over all of the neighbors incident to a vertex.
Parallel edges and self-loops are permitted.
For additional documentation, see Section 4.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Constructor Summary
ConstructorsConstructorDescriptionEdgeWeightedGraph(int V) Create an empty edge-weighted graph with V vertices.EdgeWeightedGraph(int V, int E) Create a random edge-weighted graph with V vertices and E edges with no parallel edges or self loops.EdgeWeightedGraph(int V, int E, boolean allowParallelEdgesAndSelfLoops) Create a random edge-weighted graph with V vertices and E edges.Copy constructor.EdgeWeightedGraph(In in) Create a weighted graph from input stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the edge e to this graph.adj(int v) Return the edges incident to vertex v as an Iterable.intE()Return the number of edges in this graph.edges()Return all edges in this graph as an Iterable.static voidTest client.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 graph.
-
Constructor Details
-
EdgeWeightedGraph
Create an empty edge-weighted graph with V vertices. -
EdgeWeightedGraph
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. -
EdgeWeightedGraph
Create a random edge-weighted graph with V vertices and E edges. The expected running time is proportional to V + E. -
EdgeWeightedGraph
Create a weighted graph from input stream. -
EdgeWeightedGraph
Copy constructor.
-
-
Method Details
-
V
Return the number of vertices in this graph. -
E
Return the number of edges in this graph. -
addEdge
Add the edge e to this graph. -
adj
Return the edges incident to vertex v as an Iterable. To iterate over the edges incident to vertex v, use foreach notation:for (Edge e : graph.adj(v)). -
edges
Return all edges in this graph as an Iterable. To iterate over the edges, use foreach notation:for (Edge e : graph.edges()). -
toString
Return a string representation of this graph. -
toGraphviz
Save a graphviz representation of the graph. See graphviz.org. -
main
Test client.
-