public Topological(Digraph d) { DirectedCycle directedCycle = new DirectedCycle(d); if (!directedCycle.hasCycle()) { DepthFirstOrder depthFirstOrder = new DepthFirstOrder(d); this.order = depthFirstOrder.reversePost(); } }
private int[] rank; // rank[v] = position of vertex v in topological order public Topological(Digraph G) { DirectedCycle finder = new DirectedCycle(G); if (!finder.hasCycle()) { DepthFirstOrder dfs = new DepthFirstOrder(G); order = dfs.reversePost(); rank = new int[G.V()]; int i = 0; foreach (int v in order) { rank[v] = i++; } } }
/**/ public static void main(string[] strarr) { In i = new In(strarr[0]); Digraph d = new Digraph(i); DirectedCycle directedCycle = new DirectedCycle(d); if (directedCycle.hasCycle()) { StdOut.print("Cycle: "); Iterator iterator = directedCycle.cycle().iterator(); while (iterator.hasNext()) { int i2 = ((Integer)iterator.next()).intValue(); StdOut.print(new StringBuilder().append(i2).append(" ").toString()); } StdOut.println(); } else { StdOut.println("No cycle"); } }
void Start() { Digraph G = new Digraph(txt); DirectedCycle finder = new DirectedCycle(G); if (finder.hasCycle()) { string str = "Directed cycle: "; foreach (int v in finder.Cycle()) { str += (v + " "); } print(str); } else { print("No directed cycle"); } }