Implemented TopologicalSort().