Exemplo n.º 1
0
 public BreadthFirstSearch(Graph graph)
 {
     this.graph = graph;
     traversedVertex = new bool[graph.Vertices.Count()];
     queueVertices = new Queue<int>();
     distance = new int[graph.Vertices.Count()];
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Graph graph = new Graph();
            graph.AddEdge(0, 1);
            graph.AddEdge(0, 2);
            graph.AddEdge(1, 3);
            graph.AddEdge(2, 3);
            graph.AddEdge(2, 4);
            graph.AddEdge(3, 4);            

            BreadthFirstSearch bfs = new BreadthFirstSearch(graph);
            bool isReachable = bfs.Run(graph.Vertices.First(), graph.Vertices.Last());

            if (isReachable)
            {
                Console.WriteLine(bfs.Distance[graph.Vertices.Last()]);
            }
            
            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }