public TopoSortPostorderDFS(Graph graph) { this.G = graph; res = new List <int>(); if (!G.IsDirected) { throw new Exception("TopoSort only works in directed graph."); } DirctedCycleDetection dc = new DirctedCycleDetection(graph); hasCycle = dc.IsCycle; if (hasCycle) { return; } visited = new bool[graph.V]; for (int i = 0; i < G.V; i++) { if (!visited[i]) { DFS(i); } } res.Reverse(); }
public static void Main1(string[] arg) { Graph graph = new Graph("_g.txt", true); DirctedCycleDetection cd = new DirctedCycleDetection(graph); Console.WriteLine(cd.isCycle); }