mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-23 01:28:26 +00:00
comment updated
This commit is contained in:
parent
239b8c83e4
commit
7ac458d746
|
@ -17,11 +17,11 @@ vertices: list[str] = ["a", "b", "c", "d", "e"]
|
||||||
|
|
||||||
def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[str]:
|
def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[str]:
|
||||||
"""Perform topological sort on a directed acyclic graph."""
|
"""Perform topological sort on a directed acyclic graph."""
|
||||||
|
# consider edge direction from top to bottom
|
||||||
current = start
|
current = start
|
||||||
# add current to visited
|
# add current to visited
|
||||||
visited.append(current)
|
visited.append(current)
|
||||||
neighbors = edges[current]
|
neighbors = edges[current]
|
||||||
# direction not given so consider from top to bottom
|
|
||||||
# as the current node encounter add it to the topo sort list
|
# as the current node encounter add it to the topo sort list
|
||||||
sort.append(current)
|
sort.append(current)
|
||||||
for neighbor in neighbors:
|
for neighbor in neighbors:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user