-
-
Notifications
You must be signed in to change notification settings - Fork 50.5k
Fix topological sort order #14609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix topological sort order #14609
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,8 @@ def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[st | |
| # if neighbor not in visited, visit | ||
| if neighbor not in visited: | ||
| sort = topological_sort(neighbor, visited, sort) | ||
| # if all neighbors visited add current to sort | ||
| sort.append(current) | ||
| # if all neighbors visited add current before its descendants | ||
| sort.insert(0, current) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
| # if all vertices haven't been visited select a new one to visit | ||
| if len(visited) != len(vertices): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function depends on the global |
||
| for vertice in vertices: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment seems inaccurate. At this point, the DFS has already visited all reachable descendants, and
currentis being inserted before them in the final ordering. Consider rewording it to avoid confusion.