@@ -0,0 +1,1706 @@
+package algorithms.graph;%0A%0Aimport java.util.HashSet;%0Aimport java.util.List;%0Aimport java.util.Set;%0A%0Aimport datastructures.graph.AbstractGraph;%0Aimport datastructures.graph.DirectedGraph;%0Aimport datastructures.graph.Vertex;%0Aimport datastructures.util.GraphUtil;%0A%0Apublic class DetectCycleDirectedGraph %7B%0A  private AbstractGraph%3CString%3E graph = null;%0A  private Set%3CVertex%3CString%3E%3E vertices = null;%0A  private Set%3CVertex%3CString%3E%3E whiteSet = null;%0A  private Set%3CVertex%3CString%3E%3E greySet = null;%0A  private Set%3CVertex%3CString%3E%3E blackSet = null;%0A%0A  public DetectCycleDirectedGraph() %7B%0A    graph = new DirectedGraph%3CString%3E();%0A    whiteSet = new HashSet%3CVertex%3CString%3E%3E();%0A    greySet = new HashSet%3CVertex%3CString%3E%3E();%0A    blackSet = new HashSet%3CVertex%3CString%3E%3E();%0A  %7D%0A%0A  public void constructGraph(String%5B%5D input) %7B%0A    GraphUtil.constructGraph(graph, input);%0A    vertices = graph.verticesSet();%0A  %7D%0A%0A  public boolean detectCycle() %7B%0A    whiteSet.addAll(vertices);%0A%0A    for (Vertex%3CString%3E vertex : vertices) %7B%0A      if (whiteSet.contains(vertex)) %7B%0A        if (detectCycleDFS(vertex)) %7B%0A          return true;%0A        %7D%0A      %7D%0A    %7D%0A%0A    return false;%0A  %7D%0A%0A  private boolean detectCycleDFS(Vertex%3CString%3E vertex) %7B%0A    if (vertex == null) %7B%0A      return false;%0A    %7D%0A%0A    whiteSet.remove(vertex);%0A    greySet.add(vertex);%0A%0A    List%3CVertex%3CString%3E%3E neighbours = graph.neighboursOf(vertex);%0A    for (Vertex%3CString%3E neighbour : neighbours) %7B%0A      if (whiteSet.contains(neighbour)) %7B%0A        if (detectCycleDFS(neighbour)) %7B%0A          return true;%0A        %7D%0A      %7D else if (greySet.contains(neighbour)) %7B%0A        return true;%0A      %7D%0A    %7D%0A%0A    greySet.remove(vertex);%0A    blackSet.add(vertex);%0A%0A    return false;%0A  %7D%0A%7D%0A

Add DetectCycleDirectedGraph solution