mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 08:12:02 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
12dde2f9e6
commit
f1fdd7978f
|
@ -16,6 +16,7 @@ edges: dict[str, list[str]] = {
|
||||||
|
|
||||||
vertices: list[str] = ["a", "b", "c", "d", "e"]
|
vertices: list[str] = ["a", "b", "c", "d", "e"]
|
||||||
|
|
||||||
|
|
||||||
# Perform topological sort on a DAG starting from the specified node
|
# Perform topological sort on a DAG starting from the specified node
|
||||||
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]:
|
||||||
current = start
|
current = start
|
||||||
|
@ -42,11 +43,12 @@ def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[st
|
||||||
# Return sorted list
|
# Return sorted list
|
||||||
return sort
|
return sort
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Topological Sorting from node "a" (Returns the order in bottom up approach)
|
# Topological Sorting from node "a" (Returns the order in bottom up approach)
|
||||||
sort = topological_sort("a", [], [])
|
sort = topological_sort("a", [], [])
|
||||||
|
|
||||||
# Reversing the list to get the correct topological order (Top down approach)
|
# Reversing the list to get the correct topological order (Top down approach)
|
||||||
sort.reverse()
|
sort.reverse()
|
||||||
|
|
||||||
print(sort)
|
print(sort)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user