1 parent f6ee518 commit d2e8e62Copy full SHA for d2e8e62
1 file changed
graphs/g_topological_sort.py
@@ -9,7 +9,7 @@
9
5: "socks",
10
6: "shirt",
11
7: "tie",
12
- 8: "clock",
+ 8: "watch",
13
}
14
15
graph = [[1, 4], [2, 4], [3], [], [], [4], [2, 7], [3], []]
@@ -21,27 +21,27 @@
21
def print_stack(stack, clothes):
22
order = 1
23
while stack:
24
- cur_clothe = stack.pop()
25
- print(order, clothes[cur_clothe])
+ current_clothing = stack.pop()
+ print(order, clothes[current_clothing])
26
order += 1
27
28
29
-def dfs(u, visited, graph):
+def depth_first_search(u, visited, graph):
30
visited[u] = 1
31
for v in graph[u]:
32
if not visited[v]:
33
- dfs(v, visited, graph)
+ depth_first_search(v, visited, graph)
34
35
stack.append(u)
36
37
38
-def top_sort(graph, visited):
+def topological_sort(graph, visited):
39
for v in range(len(graph)):
40
41
42
43
44
if __name__ == "__main__":
45
- top_sort(graph, visited)
+ topological_sort(graph, visited)
46
print(stack)
47
print_stack(stack, clothes)
0 commit comments