Package algs41
Class Graph
java.lang.Object
algs41.Graph
The
Graph class represents an undirected graph of vertices
named 0 through V-1.
It supports the following operations: add an edge to the graph,
iterate over all of the neighbors adjacent to a vertex.
Parallel edges and self-loops are permitted.
For additional documentation, see Section 5.1 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEdge(int v, int w) Add the undirected edge v-w to graph.adj(int v) Return the list of neighbors of vertex v as in Iterable.intdegree(int v) Returns the degree of vertexv.intE()Return the number of edges in the graph.static voidTest client.voidtoGraphviz(String filename) Save a graphviz representation of the graph.toString()Return a string representation of the graph.intV()Return the number of vertices in the graph.
-
Field Details
-
V
-
E
-
adj
-
-
Constructor Details
-
Graph
Create an empty graph with V vertices.
-
-
Method Details
-
V
Return the number of vertices in the graph. -
E
Return the number of edges in the graph. -
addEdge
Add the undirected edge v-w to graph.- Throws:
IndexOutOfBoundsException- unless both0 <= v < Vand0 <= w < V
-
adj
Return the list of neighbors of vertex v as in Iterable.- Throws:
IndexOutOfBoundsException- unless0 <= v < V
-
degree
Returns the degree of vertexv.- Parameters:
v- the vertex- Returns:
- the degree of vertex
v - Throws:
IllegalArgumentException- unless0 <= v < V
-
toString
Return a string representation of the graph. -
toGraphviz
Save a graphviz representation of the graph. See graphviz.org. -
main
Test client.
-