public class EdgeWeightedDigraph extends Object
EdgeWeightedDigraph
class represents a edgeweighted
digraph of vertices named 0 through V  1, where each
directed edge is of type DirectedEdge
and has a realvalued weight.
It supports the following two primary operations: add a directed edge
to the digraph and iterate over all of edges incident from a given vertex.
It also provides methods for returning the indegree or outdegree of a
vertex, the number of vertices V in the digraph, and
the number of edges E in the digraph.
Parallel edges and selfloops are permitted.
This implementation uses an adjacencylists representation, which
is a vertexindexed array of Bag
objects.
It uses Θ(E + V) space, where E is
the number of edges and V is the number of vertices.
All instance methods take Θ(1) time. (Though, iterating over
the edges returned by adj(int)
takes time proportional
to the outdegree of the vertex.)
Constructing an empty edgeweighted digraph with V vertices
takes Θ(V) time; constructing an edgeweighted digraph
with E edges and V vertices takes
Θ(E + V) time.
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

EdgeWeightedDigraph(EdgeWeightedDigraph G)
Initializes a new edgeweighted digraph that is a deep copy of
G . 
EdgeWeightedDigraph(In in)
Initializes an edgeweighted digraph from the specified input stream.

EdgeWeightedDigraph(int V)
Initializes an empty edgeweighted digraph with
V vertices and 0 edges. 
EdgeWeightedDigraph(int V,
int E)
Initializes a random edgeweighted digraph with
V vertices and E edges. 
Modifier and Type  Method and Description 

void 
addEdge(DirectedEdge e)
Adds the directed edge
e to this edgeweighted digraph. 
Iterable<DirectedEdge> 
adj(int v)
Returns the directed edges incident from vertex
v . 
int 
E()
Returns the number of edges in this edgeweighted digraph.

Iterable<DirectedEdge> 
edges()
Returns all directed edges in this edgeweighted digraph.

int 
indegree(int v)
Returns the number of directed edges incident to vertex
v . 
static void 
main(String[] args)
Unit tests the
EdgeWeightedDigraph data type. 
int 
outdegree(int v)
Returns the number of directed edges incident from vertex
v . 
String 
toString()
Returns a string representation of this edgeweighted digraph.

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

public EdgeWeightedDigraph(int V)
V
vertices and 0 edges.V
 the number of verticesIllegalArgumentException
 if V < 0
public EdgeWeightedDigraph(int V, int E)
V
vertices and E edges.V
 the number of verticesE
 the number of edgesIllegalArgumentException
 if V < 0
IllegalArgumentException
 if E < 0
public EdgeWeightedDigraph(In in)
in
 the input streamIllegalArgumentException
 if in
is null
IllegalArgumentException
 if the endpoints of any edge are not in prescribed rangeIllegalArgumentException
 if the number of vertices or edges is negativepublic EdgeWeightedDigraph(EdgeWeightedDigraph G)
G
.G
 the edgeweighted digraph to copypublic int V()
public int E()
public void addEdge(DirectedEdge e)
e
to this edgeweighted digraph.e
 the edgeIllegalArgumentException
 unless endpoints of edge are between 0
and V1
public Iterable<DirectedEdge> adj(int v)
v
.v
 the vertexv
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 Iterable<DirectedEdge> edges()
for (DirectedEdge e : G.edges())
.public String toString()
public static void main(String[] args)
EdgeWeightedDigraph
data type.args
 the commandline arguments