Class TopologicalOrderIterator

java.lang.Object
org.graph4j.traversal.TopologicalOrderIterator
All Implemented Interfaces:
IntIterator

public class TopologicalOrderIterator extends Object implements 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 Details

    • TopologicalOrderIterator

      public TopologicalOrderIterator(Digraph graph)
      Creates a topological order iterator for a directed graph.
      Parameters:
      graph - the input directed graph.
  • Method Details

    • hasNext

      public boolean hasNext() throws IllegalArgumentException
      Returns true if the iteration has more elements.
      Specified by:
      hasNext in interface IntIterator
      Returns:
      true if the iteration has more elements.
      Throws:
      IllegalArgumentException - if the digraph is not acyclic.
    • next

      public int next()
      Description copied from interface: IntIterator
      Returns the next element in the iteration.
      Specified by:
      next in interface IntIterator
      Returns:
      the next element in the iteration.
    • level

      public int level()
      Returns the level of the current vertex (the one returned by the next() method.
      Returns:
      the level of the current vertex.