/* DepthFirst: depth-first traversal of a graph. Pre: The graph G has been created. Post: The function Visit has been performed at each vertex of G in depth-first order. Uses: Function Traverse produces the recursive depth-first order. */ void DepthFirst(Graph G, void (*Visit)(Vertex)) { Boolean visited[MAXVERTEX]; Vertex v; for (all v in G) visited[v] = FALSE; for (all v in G) if (!visited[v]) Traverse(v, Visit); } /* Traverse: recursive traversal of a graph Pre: v is a vertex of the graph G. Post: The depth-first traversal, using function Visit, has been completed for v and for all vertices adjacent to v. Uses: Traverse recursively. */ void Traverse(Vertex v, void (*Visit)(Vertex)) { Vertex w; visited[v] = TRUE; Visit(v); for (all w adjacent to v) if (!visited[w]) Traverse(w, Visit); }