private void DFSVisit(Knoten2 v, int index, string zyklus) { int i; time += 1; v.firstTime = time; v.color = "grau"; for (i = 0; i < matrix.GetLength(1); i++) { if (matrix[index, i] == 1) { if (knoten[i].color == "weiß") { knoten[i].pred = v; DFSVisit(knoten[i], i, zyklus + i + " - "); } else if (knoten[i].color == "grau" && knoten[i] != v && knoten[i] != v.pred) { zyklus += Array.IndexOf(knoten, knoten[i]); int test = Array.IndexOf(knoten, knoten[i]); zyklus = zyklus.Substring(zyklus.IndexOf(test.ToString())); Console.WriteLine("Zyklus gefunden: " + zyklus); break; } } } v.color = "schwarz"; time += 1; v.lastTime = time; // Console.Write(index + " "); }
public void DFS() { int i; Console.Write("Tiefensuche: "); for (i = 0; i < knoten.Length; i++) { knoten[i] = new Knoten2(); knoten[i].color = "weiß"; knoten[i].pred = null; } for (i = 0; i < 1; i++) { if (knoten[i].color == "weiß") { DFSVisit(knoten[i], i, (i + " - ")); } } Console.WriteLine(); }