Example #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));
         }
     }
 }
Example #2
0
        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);
                    }
                }
            }
        }