Put the topological sort in the right order.