@brief 拓扑排序
@cost (V + E)
@note 依赖于图的深度优先遍历
from wiki
L← Empty list that will contain the sorted elements
S ← Set of all nodes with no incoming edges
while S is non-empty do
remove a node n from S
insert n into L
foreach node m with an edge e from nto m do
remove edge e from the graph
if m has no other incoming edges then
insert m into S
if graph has edges then
return error (graph has at least onecycle)
else
return L (a topologically sorted order)
转载于:https://my.oschina.net/u/572632/blog/346067