Package dsa
Class EdgeWeightedGraph
- java.lang.Object
-
- dsa.EdgeWeightedGraph
-
public class EdgeWeightedGraph extends Object
A data type to represent an undirected graph with weighted edges.
-
-
Constructor Summary
Constructors Constructor Description EdgeWeightedGraph(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(Edge e)
Adds an edgee
to this edge-weighted graph.Iterable<Edge>
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.Iterable<Edge>
edges()
Returns all the edges in this edge-weighted graph.static void
main(String[] args)
Unit tests the data type.String
toString()
Returns a string representation of this edge-weighted graph.int
V()
Returns the number of vertices in this edge-weighted graph.
-
-
-
Constructor Detail
-
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 Detail
-
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
public void addEdge(Edge e)
Adds an edgee
to this edge-weighted graph.- Parameters:
e
- the edge.
-
adj
public Iterable<Edge> adj(int v)
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
public Iterable<Edge> edges()
Returns all the edges in this edge-weighted graph.- Returns:
- all the edges in this edge-weighted graph.
-
toString
public String toString()
Returns a string representation of this edge-weighted graph.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-