private void DFS(DFSGraph graph)
 {
     for (int idx = 0; idx < graph.V; idx++)
     {
         if (visited.Count == 0 || !visited[idx])
         {
             //visited[idx] = true;
             DFS_Visit(idx, graph);
         }
     }
 }
        private void DFS_Visit(int V, DFSGraph graph)
        {
            List <int> adjList = graph.AdjList[V];

            visited[V] = true;

            for (int idx = 0; idx < adjList.Count; idx++)
            {
                if (!visited.ContainsKey(adjList[idx]) || !(visited[adjList[idx]]))
                {
                    DFS_Visit(adjList[idx], graph);
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Graph graph = CreateGraph();

            //InvokeKruskalMST();
            #region DFS
            DFSGraph g = new DFSGraph(4);
            g.AddEdge(0, 1);
            g.AddEdge(0, 2);
            g.AddEdge(1, 2);
            g.AddEdge(2, 0);
            g.AddEdge(2, 3);
            g.AddEdge(3, 3);


            DFSInGraph obj = new DFSInGraph();
            obj.DoDFS(g);

            #endregion

            Console.Read();
        }
 public void DoDFS(DFSGraph graph)
 {
     visited = new Dictionary <int, bool>(graph.V);
     DFS(graph);
 }