I know the common way to do a topological sort is using DFS with recursion. But how would you do it using stack
instead of recursion? I need to obtai
The node is 1st visited and is still in process, it's added to stack as false. These nodes are then processed from stack as LIFO, and changed to true (processed means children visited). After all children processed, while tracing path back, this node dropped from stack.
For those trying to implement this code, visited[node.second]=true;
should be moved to the 2 places where node is 1st added to stack as false. This, so that back edges leading to already traced vertices not revisited.