Implements sorting algorithm for directed acyclic as well as cyclic graphs. The directed cyclic graphs are sorted by determining the minimal amount of cyclic edges and optionally then also determining the maximum amount of groupings possible with a minimal amount of cyclic edges.