/// <summary> /// 广度优先遍历 /// </summary> public void IterateBFS(GraphNode <T> startNode, Action <GraphNode <T> > action) { if (action == null) { return; } int count = 0; var it = new BreadthFirstIterator <T>(startNode); foreach (GraphNode <T> node in it.Iterate()) { action.Invoke(node); count++; } }
public IEnumerator IterateBFSCoroutine(GraphNode <T> startNode, Action <GraphNode <T> > action, int yieldCount = 32) { if (action == null) { yield break; } var it = new BreadthFirstIterator <T>(startNode); int loopCount = 0; int lastCount = 0; foreach (GraphNode <T> node in it.Iterate()) { action.Invoke(node); loopCount++; if (loopCount - lastCount > yieldCount) { lastCount = loopCount; yield return(null); } } }