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); } } } }
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); } } } }