Created
October 21, 2021 20:54
-
-
Save khornberg/a18e4d383d06edb4b1f86efcd9b761dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import graphlib | |
def ts_sort(topological_sorter): | |
topological_sorter.prepare() | |
spaces = 0 | |
while topological_sorter: | |
nodes = topological_sorter.get_ready() | |
print(" "*spaces, nodes) | |
for node in nodes: | |
topological_sorter.done(node) | |
spaces += 2 | |
ts = graphlib.TopologicalSorter() | |
ts.add('s1', 's0') | |
ts.add('s1', 's2') | |
ts_sort(ts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment