コード例 #1
0
 public void SearchFrom(int v)
 {
     Register(new Edge(v, v));
     while (!_edges.IsEmpty())
     {
         var step = _edges.Dequeue();
         foreach (var w in _graph.Adjacents(step.To))
         {
             Register(new Edge(step.To, w));
         }
     }
 }
コード例 #2
0
ファイル: ITree.cs プロジェクト: sayon/csharp-algorithms
        public static void BFS <V, E>(IGraph <V, E> graph, Action <Node <V> > act, int idxStart)
        {
            var startNode = graph[idxStart];
            var queue     = new Queue <Node <V> >();

            queue.Enqueue(startNode);
            var visited = new bool[graph.NodesCount];

            while (queue.Count > 0)
            {
                var currentNode = queue.Dequeue();
                act(currentNode);
                visited[currentNode.Index] = true;
                foreach (var node in graph.Adjacents(currentNode))
                {
                    if (!visited[node.Index])
                    {
                        queue.Enqueue(node);
                    }
                }
            }
        }