拓扑排序:查找并返回一个图中的顶点序列,给每个顶点分配了等级以便边总是从低等级的顶点指向高等级的顶点
def topologicalSort(graph, process):
stack = LinkedStack()
visited = {}
def dfs(v, process, stack):
visited[v] = True
process(v)
for w in graph(v):
if not visited.get(w):
dfs(w, process, stack)
stack.push(v)
for v in graph:
if not visited.get(v):
dfs(v, process, stack)