Extracted Topological sort from DFS