private void Search(int fromVertexIndex)
 {
     _visited[fromVertexIndex] = true;
     foreach (var vertex in _graph.GetAdjacents(fromVertexIndex))
     {
         if (!_visited[vertex])
         {
             _edgesTo[vertex] = fromVertexIndex;
             Search(vertex);
         }
     }
 }
Exemple #2
0
        private void Search(int sourceVertexIndex)
        {
            var queue = new Queue <int>();

            queue.Enqueue(sourceVertexIndex);

            while (queue.Any())
            {
                var currentVertexIndex = queue.Dequeue();
                foreach (var vertexIndex in _graph.GetAdjacents(currentVertexIndex))
                {
                    if (_visited[vertexIndex])
                    {
                        continue;
                    }

                    _visited[vertexIndex] = true;
                    _pathTo[vertexIndex]  = currentVertexIndex;
                    queue.Enqueue(vertexIndex);
                }
            }
        }