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); } }
public Graph(ulong vertexNumber = 0) { Vertexes = new Vertex[vertexNumber]; for (ulong i = 0; i < vertexNumber; ++i) { Vertexes[i] = new Vertex(); Vertexes[i].Number = i; } }
/// Adds connection to vertex. public void AddConnection(Vertex connected) { Connections.Add(connected); }