Package dsa
Class EdgeWeightedGraph
java.lang.Object
dsa.EdgeWeightedGraph
A data type to represent an undirected graph with weighted edges.
-
Constructor Summary
ConstructorDescriptionEdgeWeightedGraph
(int V) Constructs an empty edge-weighted graph withV
vertices and 0 edges.EdgeWeightedGraph
(stdlib.In in) Constructs an edge-weighted graph from the input streamin
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an edgee
to this edge-weighted graph.adj
(int v) Returns the edges incident on vertexv
in this edge-weighted graph.int
degree
(int v) Returns the degree of vertexv
in this edge-weighted graph.int
E()
Returns the number of edges in this edge-weighted graph.edges()
Returns all the edges in this edge-weighted graph.static void
Unit tests the data type.toString()
Returns a string representation of this edge-weighted graph.int
V()
Returns the number of vertices in this edge-weighted graph.
-
Constructor Details
-
EdgeWeightedGraph
public EdgeWeightedGraph(int V) Constructs an empty edge-weighted graph withV
vertices and 0 edges.- Parameters:
V
- number of vertices.
-
EdgeWeightedGraph
public EdgeWeightedGraph(stdlib.In in) Constructs an edge-weighted graph from the input streamin
.- Parameters:
in
- the input stream.
-
-
Method Details
-
V
public int V()Returns the number of vertices in this edge-weighted graph.- Returns:
- the number of vertices in this edge-weighted graph.
-
E
public int E()Returns the number of edges in this edge-weighted graph.- Returns:
- the number of edges in this edge-weighted graph.
-
addEdge
Adds an edgee
to this edge-weighted graph.- Parameters:
e
- the edge.
-
adj
Returns the edges incident on vertexv
in this edge-weighted graph.- Parameters:
v
- the vertex.- Returns:
- the edges incident on vertex
v
in this edge-weighted graph.
-
degree
public int degree(int v) Returns the degree of vertexv
in this edge-weighted graph.- Parameters:
v
- the vertex.- Returns:
- the degree of vertex
v
in this edge-weighted graph.
-
edges
Returns all the edges in this edge-weighted graph.- Returns:
- all the edges in this edge-weighted graph.
-
toString
Returns a string representation of this edge-weighted graph. -
main
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-