예제 #1
0
        public static List <int> BFSDriver(int totalNodes, bool isDirected, int source, List <Tuple <int, int> > edges)
        {
            Graph graph = new Graph(totalNodes, isDirected);

            foreach (var edge in edges)
            {
                graph.AddEdge(edge.Item1, edge.Item2);
            }

            return(graph.BFS(source));
        }
예제 #2
0
        public void Run()
        {
            Graph g = new Graph(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);

            Console.WriteLine("Working on DFS: ");
            g.DFS(2);
            Console.WriteLine();

            g = new Graph(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);

            Console.WriteLine("Working on BFS: ");
            g.BFS(2);
            Console.WriteLine();

            Console.WriteLine("Working on Topoligical Sort: ");

            g = new Graph(6);
            g.AddEdge(5, 2);
            g.AddEdge(5, 0);
            g.AddEdge(4, 0);
            g.AddEdge(4, 1);
            g.AddEdge(2, 3);
            g.AddEdge(3, 1);

            Console.WriteLine("BFS");
            g.DFS(5);
            g.ToplogicalSort();
            Console.WriteLine();
        }