Topological Sort (DFS)
Performs a topological sort on the directed graph. This is a DFS implementation
Usage
dfs_toposort(graph: Graph)
Parameters:
graph : Graph
Graph Object
Returns:
list
Valid topological ordering
Example
from jellybeans.algos import dfs_toposortfrom jellybeans.structures import Graphg = Graph()g.add_vertex(0)g.add_vertex(1)g.add_vertex(2)g.add_vertex(3)g.add_edge(3, 2)g.add_edge(2, 1)g.add_edge(1, 0)res = dfs_toposort(g)print(res) # [3, 2, 1, 0]