public void BFS(T from, GraphEventHandler _method) { GraphEventHandler GraphHandler = _method; Queue <T> S = new Queue <T>(); List <T> F = new List <T>(); S.Enqueue(from); F.Add(from); List <int> distance = new List <int>(); distance.Add(0); int index = 0; while (S.Count != 0) { T k = S.Dequeue(); GraphHandler?.Invoke(k, distance[index]); foreach (T item in Neighbors(k)) { if (!F.Contains(item)) { S.Enqueue(item); F.Add(item); distance.Add(distance[index] + 1); } } index++; } }
private void DFPrec(T node, GraphEventHandler GraphHandler, ref List <T> F) { F.Add(node); GraphHandler?.Invoke(node); foreach (T item in Neighbors(node)) { if (!F.Contains(item)) { DFPrec(item, GraphHandler, ref F); } } }