public class DirectedCycleX extends Object
DirectedCycleX
class represents a data type for
determining whether a digraph has a directed cycle.
The hasCycle operation determines whether the digraph has
a simple directed cycle and, if so, the cycle operation
returns one.
This implementation uses a nonrecursive, queuebased algorithm. The constructor takes time proportional to V + E (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 digraph).
See DirectedCycle
for a recursive version that uses depthfirst search.
See Topological
or TopologicalX
to compute a topological order
when the digraph is acyclic.
For additional documentation, see Section 4.2 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.
Constructor and Description 

DirectedCycleX(Digraph G) 
Modifier and Type  Method and Description 

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

static void 
main(String[] args) 
public DirectedCycleX(Digraph G)
public Iterable<Integer> cycle()
null
otherwise.null
otherwisepublic boolean hasCycle()
true
if the digraph has a directed cycle, false
otherwisepublic static void main(String[] args)