private void DFSAdjacencyList(AdjacencyList al, int node, bool[] visited) { visited[node] = true; Console.WriteLine(node); foreach (int v in al.GetList(node)) { if (!visited[v]) { DFSAdjacencyList(al, v, visited); } } }
// Depth-first search public void DFS(int node) { bool[] visited = new bool[storage.Vertices]; if (storage is AdjacencyMatrix) { AdjacencyMatrix am = (AdjacencyMatrix)storage; DFSAdjacencyMatrix(am, node, visited); } if (storage is AdjacencyList) { AdjacencyList al = (AdjacencyList)storage; DFSAdjacencyList(al, node, visited); } }