Пример #1
0
        private static void DFS(Graph g)
        {
            DFS dfs = new DFS(g, 0);

            for (int i = 0; i < g.Vertices; i++)
            {
                if (dfs.Marked(i))
                {
                    Console.Write(i + " ");
                }
            }
            Console.WriteLine();


            if (dfs.Count == g.Vertices)
            {
                Console.WriteLine("Connected");
            }
            else
            {
                Console.WriteLine("Not Connected");
            }

            IEnumerable <int> path = dfs.Path(3);

            if (path != null)
            {
                path.ToList().ForEach(x => Console.Write(x + " "));
            }
            Console.WriteLine();
        }
Пример #2
0
        private static void DFS(Graph g)
        {
            DFS dfs = new DFS(g, 0);
            for (int i = 0; i < g.Vertices; i++)
            {
                if (dfs.Marked(i))
                {
                    Console.Write(i + " ");
                }
            }
            Console.WriteLine();

            if (dfs.Count == g.Vertices)
                Console.WriteLine("Connected");
            else
                Console.WriteLine("Not Connected");

            IEnumerable<int> path = dfs.Path(3);

            if (path != null)
            {
                path.ToList().ForEach(x => Console.Write(x + " "));
            }
            Console.WriteLine();
        }