Implemented depth-first search algorithm of topological sort.