void DFS(AdjList G, int v0) { InitStack(&S); Push(&S, v0); while (!IsEmpty(S)) { Pop(&S, &v); if (!visited[v]) { visit(v); visited[v] = true; for (w = FirstNeighbor(G, v); w >= 0; w = NextNeightbor(G, v, w)) { if (!visited[w]) Push(&S, w); } } } }
2023-12-31 14:29:16
void DFS(AdjList G, int v0) { InitStack(&S); Push(&S, v0); while (!IsEmpty(S)) { Pop(&S, &v); if (!visited[v]) { visit(v); visited[v] = true; for (w = FirstNeighbor(G, v); w >= 0; w = NextNeightbor(G, v, w)) { if (!visited[w]) Push(&S, w); } } } }
下一篇:图