//广度优先搜索实现求单源最短路径 void BFSMINDISTANCE(AdjList G, int u) { InitQueue(&Q); for (int i = 0; i < G.vexnum; i++) { visited[i] = false; d[i] = INFINITY; path[i] = -1; } visit(u); visited[u] = true; EnterQueue(&Q, u); while (!IsEmpty(Q)) { DeQueue(&Q, &u); for (w = FirstNeighbor(G, u); w >= 0; w = NextNeighbor(G, u, w)) { if (!visited[w]) { visited[w] = true; d[w] = d[u] + 1; path[w] = u; EnterQueue(&Q, w); } } } }