DirectedGraph { protected void topoSort(final Vertex<E> v, Vector<Vertex<E>> visited) { for (Vertex<E> a : getAdjacentVertices(v)) { if (!visited.contains(a)) { topoSort(a, visited); } } visited.insertElementAt(v, 0); } DirectedGraph(); Vector<String> listEdges(); void addVertex(Vertex<E> v); void addEdge(Vertex<E> a, Vertex<E> b); void addEdge(Vertex<E> a, Vertex<E> b, F data); void addEdge(String aLabel, String bLabel); void addEdge(String aLabel, String bLabel, F data); F getEdgeData(Vertex<E> v1, Vertex<E> v2); Vector<F> getAllEdgeData(Vertex<E> v1, Vertex<E> v2); F getEdgeData(E vData1, E vData2); Vector<F> getAllEdgeData(E vData1, E vData2); boolean isStronglyConnected(); boolean isConnected(); Vector<Vertex<E>> getAdjacentVertices(final Vertex<E> v); void removeVertex(final Vertex<E> v); Vector<Vertex<E>> topoSort(final Vertex<E> v); Vector<Vertex<E>> topoSort(final String vLabel); Vertex<E> getVertexByLabel(final String vLabel); Vertex<E> getVertexByData(final E vData); Set<Vertex<E>> sources(); Set<Vertex<E>> from(final Vertex<E> v); Set<Vertex<E>> from(E vData); Set<Vertex<E>> to(Vertex<E> v); Set<Vertex<E>> to(E vData); Set<Vertex<E>> into(Vertex<E> v); Set<Vertex<E>> into(E vData); Vector<Vertex<E>> getTopoSort(); final Set<Vertex<E>> getVertices(); final Set<Edge<E, F>> getEdges();  }
@Test public void testTopoSortVertexOfEVectorOfVertex() { Vector<Vertex<String>> result = new Vector<Vertex<String>>(); connect.topoSort(a, result); assertTrue(result.get(0) == a); assertTrue(result.get(1) == c); assertTrue(result.get(2) == b); }
@Test public void testTopoSortVertexOfE() { Vector<Vertex<String>> result = connect.topoSort(a); assertTrue(result.get(0) == a); assertTrue(result.get(1) == c); assertTrue(result.get(2) == b); assertTrue(result.get(3) == d); assertTrue(result.get(result.size()-1) == f); }