Topological sort

A topological sort of a dag G = (V,E) is a linear ordering of all its vertices such that if G contains an edge (u,v) then u appears before v in the ordering.  (If the graph is no acyclic, then no linear ordering is possible).

Topological-sort(G)
1  call DFS(G) to compute finishing time f[v] for each vertex v.
2  as each vertex is finished, insert it onto the front of a linke list.
3  return the linked list of vertices.