# Author: Phyllipe Bezerra (https://github.com/pmba)

clothes = {
    0: "underwear",
    1: "pants",
    2: "belt",
    3: "suit",
    4: "shoe",
    5: "socks",
    6: "shirt",
    7: "tie",
    8: "clock",
}

graph = [[1, 4], [2, 4], [3], [], [], [4], [2, 7], [3], []]

visited = [0 for x in range(len(graph))]
stack = []


def print_stack(stack, clothes):
    order = 1
    while stack:
        cur_clothe = stack.pop()
        print(order, clothes[cur_clothe])
        order += 1


def dfs(u, visited, graph):
    visited[u] = 1
    for v in graph[u]:
        if not visited[v]:
            dfs(v, visited, graph)

    stack.append(u)


def top_sort(graph, visited):
    for v in range(len(graph)):
        if not visited[v]:
            dfs(v, visited, graph)


if __name__ == "__main__":
    top_sort(graph, visited)
    print(stack)
    print_stack(stack, clothes)

@@ -198,13 +198,13 @@
 8: %22
-clock
+watch
 %22,%0A%7D
@@ -395,23 +395,29 @@
      cur
+rent
 _cloth
-e
+ing
  = stack
@@ -459,15 +459,21 @@
 %5Bcur
+rent
 _cloth
-e
+ing
 %5D)%0A 
@@ -497,18 +497,33 @@
 %0A%0A%0Adef d
-fs
+epth_first_search
 (u, visi
@@ -609,34 +609,49 @@
 %5D:%0A            d
-fs
+epth_first_search
 (v, visited, gra
@@ -680,24 +680,32 @@
 u)%0A%0A%0Adef top
+ological
 _sort(graph,
@@ -791,10 +791,25 @@
    d
-fs
+epth_first_search
 (v, 
@@ -860,16 +860,24 @@
 %0A    top
+ological
 _sort(gr

Update g_topological_sort.py (#1873)