public static IEnumerable <T> BFS <T>(this IGraph <T> graph, T startVertex, HashSet <T> visitedVertices, Action <T> lastVertexAction) where T : IEquatable <T> { var queue = new QueueOnArray <T>(); queue.Enqueue(startVertex); while (!queue.IsEmpty) { var current = queue.Dequeue(); if (!visitedVertices.Contains(current)) { visitedVertices.Add(current); var noChildren = true; foreach (var edge in graph.EdgesOf(current)) { noChildren = false; queue.Enqueue(edge.Target); } if (noChildren) { lastVertexAction(current); } yield return(current); } } }
public void QueueOnArray_DequeueFromEmptyQueueTest() { var queue = new QueueOnArray <string>(); queue.Dequeue(); }