public class EdgeWeightedDirectedCycle extends Object
EdgeWeightedDirectedCycle
class represents a data type for
determining whether an edgeweighted digraph has a directed cycle.
The hasCycle operation determines whether the edgeweighted
digraph has a directed cycle and, if so, the cycle operation
returns one.
This implementation uses depthfirst search. The constructor takes Θ(V + E) time in the worst case, where V is the number of vertices and E is the number of edges. Each instance method takes Θ(1) time. It uses Θ(V) extra space (not including the edgeweighted digraph).
See Topological
to compute a topological order if the
edgeweighted digraph is acyclic.
For additional documentation, see Section 4.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

EdgeWeightedDirectedCycle(EdgeWeightedDigraph G)
Determines whether the edgeweighted digraph
G has a directed cycle and,
if so, finds such a cycle. 
Modifier and Type  Method and Description 

Iterable<DirectedEdge> 
cycle()
Returns a directed cycle if the edgeweighted digraph has a directed cycle,
and
null otherwise. 
boolean 
hasCycle()
Does the edgeweighted digraph have a directed cycle?

static void 
main(String[] args)
Unit tests the
EdgeWeightedDirectedCycle data type. 
public EdgeWeightedDirectedCycle(EdgeWeightedDigraph G)
G
has a directed cycle and,
if so, finds such a cycle.G
 the edgeweighted digraphpublic boolean hasCycle()
true
if the edgeweighted digraph has a directed cycle,
false
otherwisepublic Iterable<DirectedEdge> cycle()
null
otherwise.null
otherwisepublic static void main(String[] args)
EdgeWeightedDirectedCycle
data type.args
 the commandline arguments