private static void Dfs(Vertex vertex, Color currentColor, Color[] colors)
 {
     switch (colors[vertex.Number])
     {
         case Color.noColor:
         {
             colors[vertex.Number] = currentColor;
             break;
         }
         default:
         {
             if (colors[vertex.Number] != currentColor)
             {
                 for (var i = 0; i < colors.Length; ++i)
                 {
                     colors[i] = Color.firstColor;
                 }
             }
             return;
         }
     }
     foreach (var nextVertex in vertex.Connections)
     {
         Dfs(nextVertex, changeColor(currentColor), colors);
     }
 }
Exemplo n.º 2
0
 public Graph(ulong vertexNumber = 0)
 {
     Vertexes = new Vertex[vertexNumber];
     for (ulong i = 0; i < vertexNumber; ++i)
     {
         Vertexes[i] = new Vertex();
         Vertexes[i].Number = i;
     }
 }
Exemplo n.º 3
0
 /// Adds connection to vertex.
 public void AddConnection(Vertex connected)
 {
     Connections.Add(connected);
 }