Skip to content

Commit d2e8e62

Browse files
authored
Update g_topological_sort.py (TheAlgorithms#1873)
1 parent f6ee518 commit d2e8e62

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

graphs/g_topological_sort.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
5: "socks",
1010
6: "shirt",
1111
7: "tie",
12-
8: "clock",
12+
8: "watch",
1313
}
1414

1515
graph = [[1, 4], [2, 4], [3], [], [], [4], [2, 7], [3], []]
@@ -21,27 +21,27 @@
2121
def print_stack(stack, clothes):
2222
order = 1
2323
while stack:
24-
cur_clothe = stack.pop()
25-
print(order, clothes[cur_clothe])
24+
current_clothing = stack.pop()
25+
print(order, clothes[current_clothing])
2626
order += 1
2727

2828

29-
def dfs(u, visited, graph):
29+
def depth_first_search(u, visited, graph):
3030
visited[u] = 1
3131
for v in graph[u]:
3232
if not visited[v]:
33-
dfs(v, visited, graph)
33+
depth_first_search(v, visited, graph)
3434

3535
stack.append(u)
3636

3737

38-
def top_sort(graph, visited):
38+
def topological_sort(graph, visited):
3939
for v in range(len(graph)):
4040
if not visited[v]:
41-
dfs(v, visited, graph)
41+
depth_first_search(v, visited, graph)
4242

4343

4444
if __name__ == "__main__":
45-
top_sort(graph, visited)
45+
topological_sort(graph, visited)
4646
print(stack)
4747
print_stack(stack, clothes)

0 commit comments

Comments
 (0)