Class for Topological sorting