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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

GIT BFS< OutAdjIt, Queuetype, Mark ><br />

algorithm(const Queuetype& q, Mark& ma, const OutAdjIt& ai);<br />

3. Operations<br />

creates an instance algorithm of this class bound to the queue q,<br />

data accessor ma and the adjacency iterator ai representing the<br />

source node of the breadth first traversal.<br />

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

OutAdjIt algorithm.current( ) returns the “current” iterator.<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 />

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

4. Example<br />

gives direct access to internal Queue.<br />

This example shows how to implement an algorithmic iterator for breadth first search:<br />

class BFS_It {<br />

AdjIt<br />

_source;<br />

node_array _handler;<br />

node_array_da _mark;<br />

queue _q;<br />

GIT_BFS _search;<br />

public:<br />

BFS_It(graph& G) :<br />

_source(AdjIt(G)), _handler(G,false),<br />

_mark(_handler), _search(_q,_mark)<br />

{<br />

_search.get_queue().clear();<br />

_search.get_queue().append(_source);<br />

}<br />

bool valid() const { return !_search.finished(); }<br />

node get_node() const { return _search.current().get_node(); }<br />

BFS_It& operator++() {<br />

_search.next(); return *this; }<br />

};

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

Saved successfully!

Ooh no, something went wrong!