public class EdgeWeightedDigraph extends Object
DirectedEdge and has a real-valued 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 number of vertices V and the number
of edges E. Parallel edges and self-loops are permitted.
This implementation uses an adjacency-lists representation, which is a vertex-indexed array of @link{Bag} objects. All operations take constant time (in the worst case) except iterating over the edges incident from a given vertex, which takes time proportional to the number of such edges.
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 edge-weighted digraph that is a deep copy of G.
|
EdgeWeightedDigraph(edu.princeton.cs.introcs.In in)
Initializes an edge-weighted digraph from an input stream.
|
EdgeWeightedDigraph(int V)
Initializes an empty edge-weighted digraph with V vertices and 0 edges.
|
EdgeWeightedDigraph(int V,
int E)
Initializes a random edge-weighted digraph with V vertices and E edges.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(DirectedEdge e)
Adds the directed edge e to the edge-weighted digraph.
|
Iterable<DirectedEdge> |
adj(int v)
Returns the directed edges incident from vertex v.
|
int |
E()
Returns the number of edges in the edge-weighted digraph.
|
Iterable<DirectedEdge> |
edges()
Returns all directed edges in the edge-weighted digraph.
|
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 the edge-weighted digraph.
|
int |
V()
Returns the number of vertices in the edge-weighted digraph.
|
public EdgeWeightedDigraph(int V)
IllegalArgumentException - if V < 0public EdgeWeightedDigraph(int V,
int E)
IllegalArgumentException - if V < 0IllegalArgumentException - if E < 0public EdgeWeightedDigraph(edu.princeton.cs.introcs.In in)
in - the input streamIndexOutOfBoundsException - if the endpoints of any edge are not in prescribed rangeIllegalArgumentException - if the number of vertices or edges is negativepublic EdgeWeightedDigraph(EdgeWeightedDigraph G)
G - the edge-weighted graph to copypublic int V()
public int E()
public void addEdge(DirectedEdge e)
e - the edgepublic Iterable<DirectedEdge> adj(int v)
v - the vertexIndexOutOfBoundsException - unless 0 <= v < Vpublic Iterable<DirectedEdge> edges()
public int outdegree(int v)
v - the vertexIndexOutOfBoundsException - unless 0 <= v < Vpublic String toString()
public static void main(String[] args)
Copyright © 2014. All Rights Reserved.