Package dsa
Class DiGraph
- java.lang.Object
-
- dsa.DiGraph
-
public class DiGraph extends Object
A data type to represent a directed graph.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(int v, int w)
Adds the directed edgev→w
to this digraph.Iterable<Integer>
adj(int v)
Returns the vertices adjacent from vertexv
in this digraph.int
E()
Returns the number of edges in this digraph.int
inDegree(int v)
Returns the in-degree of vertexv
in this digraph.static void
main(String[] args)
Unit tests the data type.int
outDegree(int v)
Returns the out-degree of vertexv
in this digraph.String
toString()
Returns a string representation of this digraph.int
V()
Returns the number of vertices in this digraph.
-
-
-
Method Detail
-
V
public int V()
Returns the number of vertices in this digraph.- Returns:
- the number of vertices in this digraph.
-
E
public int E()
Returns the number of edges in this digraph.- Returns:
- the number of edges in this digraph.
-
addEdge
public void addEdge(int v, int w)
Adds the directed edgev→w
to this digraph.- Parameters:
v
- the from vertex.w
- the to vertex.
-
adj
public Iterable<Integer> adj(int v)
Returns the vertices adjacent from vertexv
in this digraph.- Parameters:
v
- the vertex.- Returns:
- the vertices adjacent from vertex
v
in this digraph.
-
outDegree
public int outDegree(int v)
Returns the out-degree of vertexv
in this digraph.- Parameters:
v
- the vertex.- Returns:
- the out-degree of vertex
v
in this digraph.
-
inDegree
public int inDegree(int v)
Returns the in-degree of vertexv
in this digraph.- Parameters:
v
- the vertex.- Returns:
- the in-degree of vertex
v
in this digraph.
-
toString
public String toString()
Returns a string representation of this digraph.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-