Ejemplo n.º 1
0
        private void IterateOnVertices(IteratorPack currentPack)
        {
            var currentVertex = currentPack.vertex;
            var component     = currentPack.component;

            visitedVertices[currentVertex] = true;
            component.Vertices.Add(currentVertex);

            foreach (Vertex adjacent in currentVertex.Adjacents)
            {
                if (!visitedVertices[adjacent])
                {
                    var newPack = new IteratorPack(adjacent, component);
                    verticesToUtil.Push(newPack);
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// constructs components from the graph
 /// </summary>
 /// <param name="graph"></param>
 public void Process()
 {
     foreach (Vertex vertex in graph.Vertices)
     {
         if (!visitedVertices[vertex])
         {
             var component = new Component();
             Components.Add(component);
             var firstPack = new IteratorPack(vertex, component);
             verticesToUtil.Push(firstPack);
             while (verticesToUtil.Count > 0)
             {
                 IterateOnVertices(verticesToUtil.Pop());
             }
         }
     }
 }