public class Digraph extends Object
Digraph
class represents a directed graph of vertices
named 0 through V  1.
It supports the following two primary operations: add an edge to the digraph,
iterate over all of the vertices adjacent from a given vertex.
Parallel edges and selfloops are permitted.
This implementation uses an adjacencylists representation, which
is a vertexindexed array of Bag
objects.
All operations take constant time (in the worst case) except
iterating over the vertices adjacent from a given vertex, which takes
time proportional to the number of such vertices.
For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

Digraph(Digraph G)
Initializes a new digraph that is a deep copy of the specified digraph.

Digraph(In in)
Initializes a digraph from the specified input stream.

Digraph(int V)
Initializes an empty digraph with V vertices.

Modifier and Type  Method and Description 

void 
addEdge(int v,
int w)
Adds the directed edge v→w to this digraph.

Iterable<Integer> 
adj(int v)
Returns the vertices adjacent from vertex
v in this digraph. 
int 
E()
Returns the number of edges in this digraph.

int 
indegree(int v)
Returns the number of directed edges incident to vertex
v . 
static void 
main(String[] args)
Unit tests the
Digraph data type. 
int 
outdegree(int v)
Returns the number of directed edges incident from vertex
v . 
Digraph 
reverse()
Returns the reverse of the digraph.

String 
toString()
Returns a string representation of the graph.

int 
V()
Returns the number of vertices in this digraph.

public Digraph(int V)
V
 the number of verticesIllegalArgumentException
 if V < 0
public Digraph(In in)
in
 the input streamIllegalArgumentException
 if the endpoints of any edge are not in prescribed rangeIllegalArgumentException
 if the number of vertices or edges is negativeIllegalArgumentException
 if the input stream is in the wrong formatpublic Digraph(Digraph G)
G
 the digraph to copypublic int V()
public int E()
public void addEdge(int v, int w)
v
 the tail vertexw
 the head vertexIllegalArgumentException
 unless both 0 <= v < V
and 0 <= w < V
public Iterable<Integer> adj(int v)
v
in this digraph.v
 the vertexv
in this digraph, as an iterableIllegalArgumentException
 unless 0 <= v < V
public int outdegree(int v)
v
.
This is known as the outdegree of vertex v
.v
 the vertexv
IllegalArgumentException
 unless 0 <= v < V
public int indegree(int v)
v
.
This is known as the indegree of vertex v
.v
 the vertexv
IllegalArgumentException
 unless 0 <= v < V
public Digraph reverse()
public String toString()
public static void main(String[] args)
Digraph
data type.args
 the commandline arguments