void DFS(int vertex, bool[] mark, DirectedGraph Graph) { mark[vertex] = true; for (int i = 0; i < Graph.GetVertexDegree(vertex); ++i) if (!mark[Graph.GetEdge(vertex, i).End]) DFS(Graph.GetEdge(vertex, i).End, mark, Graph); _topologicalSort.Add(vertex); }
void AddStrongConnectedComponent(int vertex, int[] mark, DirectedGraph Graph) { mark[vertex] = StrongConnectedComponentCount; _strongConnectedComponentVertices[StrongConnectedComponentCount].Add(vertex); for (int i = 0; i < Graph.GetVertexDegree(vertex); ++i) if (mark[Graph.GetEdge(vertex, i).End] == StrongConnectedComponentCount || mark[Graph.GetEdge(vertex, i).End] == -1) { _strongConnectedComponentEdges[StrongConnectedComponentCount].Add(Graph.GetEdge(vertex, i).Reverse()); if (mark[Graph.GetEdge(vertex, i).End] == -1) AddStrongConnectedComponent(Graph.GetEdge(vertex, i).End, mark, Graph); } }