Package dsa

Class 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.
    • Constructor Detail

      • DiCycle

        public DiCycle​(DiGraph G)
        Determines whether the digraph G has a directed cycle and, if so, finds such a cycle.
        Parameters:
        G - the digraph.
    • Method Detail

      • hasCycle

        public boolean hasCycle()
        Returns true if a directed cycle was detected, and false otherwise.
        Returns:
        true if a directed cycle was detected, and false otherwise.
      • cycle

        public Iterable<Integer> cycle()
        Returns a directed cycle, or null.
        Returns:
        a directed cycle, or null.
      • main

        public static void main​(String[] args)
        Unit tests the data type.
        Parameters:
        args - the command-line arguments.