mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-04-08 06:45:54 +00:00
Fixed
This commit is contained in:
parent
d0e0ea1d47
commit
3d3d5aad65
@ -21,16 +21,16 @@ def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[st
|
|||||||
current = start
|
current = start
|
||||||
# Mark the current node as visited
|
# Mark the current node as visited
|
||||||
visited.append(current)
|
visited.append(current)
|
||||||
# List of all neighbours of current node
|
# List of all neighbors of current node
|
||||||
neighbors = edges[current]
|
neighbors = edges[current]
|
||||||
|
|
||||||
# Traverse all neighbours of the current node
|
# Traverse all neighbors of the current node
|
||||||
for neighbor in neighbors:
|
for neighbor in neighbors:
|
||||||
# Recursively visit each unvisited neighbour
|
# Recursively visit each unvisited neighbor
|
||||||
if neighbor not in visited:
|
if neighbor not in visited:
|
||||||
sort = topological_sort(neighbor, visited, sort)
|
sort = topological_sort(neighbor, visited, sort)
|
||||||
|
|
||||||
# After visiting all neigbours, add the current node to the sorted list
|
# After visiting all neigbors, add the current node to the sorted list
|
||||||
sort.append(current)
|
sort.append(current)
|
||||||
|
|
||||||
# If there are some nodes that were not visited (disconnected components)
|
# If there are some nodes that were not visited (disconnected components)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user