private void DFSUtil(int vert, bool[] visited, WeightedDiAdjacencyMatrix matrix) { visited[vert] = true; Console.Write((vert + 1) + " "); var neighbours = matrix.Neighbours(vert + 1); foreach (var item in neighbours) { if (!visited[item - 1]) { DFSUtil(item - 1, visited, matrix); } } }
private void FillOrder(int v, bool[] visited, Stack <int> stack, WeightedDiAdjacencyMatrix matrix) { // Mark the current node as visited and print it visited[v] = true; // Recur for all the vertices adjacent to this vertex var neighbours = matrix.Neighbours(v + 1); foreach (var item in neighbours) { if (!visited[item - 1]) { FillOrder(item - 1, visited, stack, matrix); } } // All vertices reachable from v are processed by now, // push v to Stack stack.Push(v); }