31.01.2014 Views

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

Version 5.0 The LEDA User Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

• indegree stores for every node that corresponds to any iterator the number of incoming<br />

edges (has to be to computed before)<br />

• Queuetype is a queue parameterized with elements of type OutAdjIt<br />

<strong>The</strong> underlying graph need not be acyclic. Whether or not it is acyclic can be tested after<br />

execution of the algorithm (function cycle found()).<br />

3. Operations<br />

void algorithm.next( ) Performs one iteration of the core loop of the algorithm.<br />

More specifically, the first element of<br />

get queue() is removed from the queue, and every<br />

immediate successor n of this node for which currently<br />

holds get(indeg,n)==0 is inserted in get queue().<br />

void algorithm.finish algo( )<br />

executes the algorithm until finished( ) is true, i.e.<br />

exactly if the queue is empty.<br />

bool algorithm.finished( ) returns true if the internal queue is empty.<br />

OutAdjIt algorithm.current( ) returns the current adjacency iterator.<br />

Queuetype& algorithm.get queue( )<br />

bool algorithm.cycle found( )<br />

void algorithm.reset acyclic( )<br />

4. Implementation<br />

gives direct access to internal queue.<br />

returns true if a cycle was found.<br />

resets the internal flag that a cycle was found.<br />

<strong>The</strong> asymptotic complexity is O(m + n), where m is the number of edges and n the<br />

number of nodes.<br />

5. Example<br />

This algorithm performs a normal topological sort if the queue is initialized by the set of<br />

all nodes with indegree zero:<br />

Definition of algorithm, where indeg is a data accessor that provides full data access to<br />

the number of incoming edges for each node:<br />

GIT_TOPOSORT algorithm(indeg);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!