Step through the C++ from the DAG-TopologicalSort demo. DFS starts from each unvisited node in alphabetical order. A node is pushed onto sorted_stack only after everything it points to has been pushed, so popping the stack gives an order where every arrow points forward.
visitedrecursion_stackThe code is shortened from the activity version: parsing is left out, and the parameter lists are trimmed. The two sets and the stack are the same.