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