Пример #1
0
        static void TraverseBreadthFirst(Digraph g, bool[] visited, Queue <int> queue)
        {
            int v = queue.Dequeue();

            if (!visited[v])
            {
                Console.WriteLine(v);
                visited[v] = true;

                foreach (var adjacent in g.GetAdjacentVertices(v))
                {
                    queue.Enqueue(adjacent);
                }
            }

            if (queue.Count > 0)
            {
                TraverseBreadthFirst(g, visited, queue);
            }
        }