ObjectEdgeWeightedGraph
public class 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 | |
|---|---|
EdgeWeightedGraph(EdgeWeightedGraph G)
Copy constructor. |
|
EdgeWeightedGraph(In in)
Create a weighted graph from input stream. |
|
EdgeWeightedGraph(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. |
|
| Method Summary | |
|---|---|
void |
addEdge(Edge e)
Add the edge e to this graph. |
Iterable<Edge> |
adj(int v)
Return the edges incident to vertex v as an Iterable. |
int |
E()
Return the number of edges in this graph. |
Iterable<Edge> |
edges()
Return all edges in this graph as an Iterable. |
static void |
main(String[] args)
Test client. |
String |
toString()
Return a string representation of this graph. |
int |
V()
Return the number of vertices in this graph. |
| Methods inherited from class Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public EdgeWeightedGraph(int V)
public EdgeWeightedGraph(int V,
int E)
public EdgeWeightedGraph(In in)
public EdgeWeightedGraph(EdgeWeightedGraph G)
| Method Detail |
|---|
public int V()
public int E()
public void addEdge(Edge e)
public Iterable<Edge> adj(int v)
public Iterable<Edge> edges()
public String toString()
toString in class Objectpublic static void main(String[] args)