示例#1
0
        public static void bfs(GraphList g, int vertex)
        {
            BreadthFirstSearch search = new BreadthFirstSearch(g, vertex);

            for (int v = 0; v < g.V(); v++)
            {
                Console.Write(vertex + " To " + v + ": ");
                if (search.HasPathTo(v))
                {
                    foreach (int x in search.PathTo(v))
                    {
                        if (x == vertex)
                        {
                            Console.Write(x);
                        }
                        else
                        {
                            Console.Write("-" + x);
                        }
                    }
                }
                else
                {
                    Console.Write("No path");
                }

                Console.WriteLine();
            }
        }