sorts.topological_sort¶
Topological Sort on Directed Acyclic Graph(DAG)
https://en.wikipedia.org/wiki/Topological_sorting https://en.wikipedia.org/wiki/Directed_acyclic_graph
- Note: topological_sort() sorts a directed acyclic graph so topological_sort(2, 1, 3)
should fail.
Attributes¶
Functions¶
|
Perform topological sort on a directed acyclic graph. |
Module Contents¶
- sorts.topological_sort.topological_sort(start: str, visited: list[str], sort: list[str]) list[str]¶
Perform topological sort on a directed acyclic graph.
>>> topological_sort('a', [], []) ['c', 'd', 'e', 'b', 'a']
>>> topological_sort("a", "b", "c") Traceback (most recent call last): ... ValueError: visited must be a list
>>> topological_sort("a", [], "c") Traceback (most recent call last): ... ValueError: sort must be a list
- sorts.topological_sort.sort = []¶