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