private void IdentifyConnectedComponents() { var order = new DepthFirstOrder(_graph.Reverse()); foreach (var vertex in order.ReversePostOrder()) { if (!_marked[vertex]) { Search(vertex); _count++; } } }
public TopologicalSort(DirectedGraph graph) { if (graph == null || graph.Vertices == 0) { throw new ArgumentException(); } var graphCycle = new DepthFirstCycle(graph); if (graphCycle.HasCycle()) { throw new InvalidOperationException(); } var graphOrder = new DepthFirstOrder(graph); Order = graphOrder.ReversePostOrder(); }