BubbleSort(A[1 ... n])
- for i <- 1 to length(A)
- for j <- length(A) downto i+1
- if A[j] < A[j-1]
- exchange (A[j],A[j-1])
TOPO-Sort(G=(V,E))
- DFS(G)
- As each vertex is marked in line 7, insert it into the front of a linked list.
DFS(G=(V,E))
- mark each vertex with a 0
- count <- 0
- for each vertex in V do
- if v is marked with a 0
- dfs(v)
dfs(v)
- count <- count + 1
- mark v with count
- for each vertex w in V adjacent to v do
- if w is marked with a 0
- dfs(w)
- count <- count + 1
- mark v with count