Before we start the implementation, just to highlight again
Topological sorting only works for DAG (directed acyclic graph) : a directed graph with no directed cycles
Create sample graph
- A must come before B and C
- Both B and C must come before D
- B and C are interchangeable since there is no edge between them
- D must come before E
This helper function will assign topological number to a given vertex.
Finally, a driver function to trigger topological sorting.
Now each vertex is assigned with a number to form the topological sequence.