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.
- 
Field SummaryFields
- 
Constructor SummaryConstructorsConstructorDescriptionEdgeWeightedGraph(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 SummaryModifier 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.
- 
Field Details- 
V
- 
E
- 
adj
 
- 
- 
Constructor Details- 
EdgeWeightedGraphCreate an empty edge-weighted graph with V vertices.
- 
EdgeWeightedGraphCreate 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.
- 
EdgeWeightedGraphCreate a random edge-weighted graph with V vertices and E edges. The expected running time is proportional to V + E.
- 
EdgeWeightedGraphCreate a weighted graph from input stream.
- 
EdgeWeightedGraphCopy constructor.
 
- 
- 
Method Details- 
VReturn the number of vertices in this graph.
- 
EReturn the number of edges in this graph.
- 
addEdgeAdd the edge e to this graph.
- 
adjReturn 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)).
- 
edgesReturn all edges in this graph as an Iterable. To iterate over the edges, use foreach notation:for (Edge e : graph.edges()).
- 
toStringReturn a string representation of this graph.
- 
toGraphvizSave a graphviz representation of the graph. See graphviz.org.
- 
mainTest client.
 
-