Esempio n. 1
0
 // 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);
     }
 }
Esempio n. 2
0
        private void DFSAdjacencyMatrix(AdjacencyMatrix am, int node, bool[] visited)
        {
            visited[node] = true;
            Console.WriteLine(node);
            BitArray list = am.GetBitArray(node);

            for (int i = 0; i < list.Length; i++)
            {
                if (list[i] && !visited[i])
                {
                    DFSAdjacencyMatrix(am, i, visited);
                }
            }
        }