Package dsa
Class DiCycle
- java.lang.Object
-
- dsa.DiCycle
-
public class DiCycle extends Object
An immutable data type to determine whether a digraph has a directed cycle and, if so, find such a cycle.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterable<Integer>
cycle()
Returns a directed cycle, ornull
.boolean
hasCycle()
Returnstrue
if a directed cycle was detected, andfalse
otherwise.static void
main(String[] args)
Unit tests the data type.
-
-
-
Constructor Detail
-
DiCycle
public DiCycle(DiGraph G)
Determines whether the digraphG
has a directed cycle and, if so, finds such a cycle.- Parameters:
G
- the digraph.
-
-
Method Detail
-
hasCycle
public boolean hasCycle()
Returnstrue
if a directed cycle was detected, andfalse
otherwise.- Returns:
true
if a directed cycle was detected, andfalse
otherwise.
-
cycle
public Iterable<Integer> cycle()
Returns a directed cycle, ornull
.- Returns:
- a directed cycle, or
null
.
-
main
public static void main(String[] args)
Unit tests the data type.- Parameters:
args
- the command-line arguments.
-
-