Toposort algorithm implemented