Package org.graph4j.traversal
Class TopologicalOrderIterator
java.lang.Object
org.graph4j.traversal.TopologicalOrderIterator
- All Implemented Interfaces:
IntIterator
A topological order iterator for a directed acyclic graph (DAG).
In a topological ordering, each vertex appears before all the other vertices
it has an outgoing edge to.
If the input digraph is not acyclic, the
hasNext() method will throw
an IllegalArgumentException when the ordering cannot be continued,
without being complete.- Author:
- Cristian Frăsinaru
-
Constructor Summary
ConstructorsConstructorDescriptionTopologicalOrderIterator(Digraph graph) Creates a topological order iterator for a directed graph. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.graph4j.util.IntIterator
remove
-
Constructor Details
-
TopologicalOrderIterator
Creates a topological order iterator for a directed graph.- Parameters:
graph- the input directed graph.
-
-
Method Details
-
hasNext
Returnstrueif the iteration has more elements.- Specified by:
hasNextin interfaceIntIterator- Returns:
trueif the iteration has more elements.- Throws:
IllegalArgumentException- if the digraph is not acyclic.
-
next
public int next()Description copied from interface:IntIteratorReturns the next element in the iteration.- Specified by:
nextin interfaceIntIterator- Returns:
- the next element in the iteration.
-
level
public int level()Returns the level of the current vertex (the one returned by thenext()method.- Returns:
- the level of the current vertex.
-