广度优先搜索求单源最短路径
//广度优先搜索实现求单源最短路径 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); } } } }
努力的意义就是放眼望去以后都是喜欢的人和事......