GraphUtil { public static <V extends IVertex, E extends IEdge<V>> IVertex[] getTopologicalSort (IGraph<V, E> graph) { IVertex[] rgVertices = new IVertex[graph.getVerticesCount ()]; Iterable<V> setNoOutgoing = getLeafVertices (graph); Map<V, Boolean> map = new HashMap<> (); for (V v : setNoOutgoing) GraphUtil.getTopologicalSortVisit (graph, v, map, rgVertices, new Int ()); return rgVertices; }  static Collection<V> getRootVertices(IGraph<V, E> graph); static Collection<V> getLeafVertices(IGraph<V, E> graph); static Collection<V> getSuccessors(IGraph<V, E> graph, V vertex); static Collection<V> getPredecessors(IGraph<V, E> graph, V vertex); static Collection<V> getNeighbors(IGraph<V, E> graph, V vertex); static int getDegree(IGraph<V, E> graph, V vertex, EDegree mode); static Iterable<VertexWithDegree<V, E>> getVerticesWithDegree(IGraph<V, E> graph, EDegree mode); static Iterable<V> getVerticesSortedByDegree(IGraph<V, E> graph, EDegree mode, boolean bSortAscending); static IVertex[] getTopologicalSort(IGraph<V, E> graph); static boolean isTopologicalOrder(IGraph<V, E> graph, Iterable<V> listVertices);  }
@Test public void testGetTopologicalSort () { for (IVertex v : GraphUtil.getTopologicalSort (m_graph)) System.out.println (v); }