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.

8.2 Bounded Priority Queues ( b priority queue )<br />

1. Definition<br />

An instance Q of the parameterized data type b priority queue is a collection of items<br />

(type b pq item). Every item contains a priority from a fixed interval [a..b] of integers<br />

(type int) and an information from an arbitrary type I. <strong>The</strong> number of items in Q is<br />

called the size of Q. If Q has size zero it is called the empty priority queue. We use 〈p, i〉<br />

to denote a b pq item with priority p ∈ [a..b] and information i.<br />

Remark: Iteration over the elements of Q using iteration macros such as forall is not<br />

supported.<br />

#include < <strong>LEDA</strong>/core/b prio.h ><br />

2. Creation<br />

b priority queue Q(int a, int b);<br />

creates an instance Q of type b priority queue with key type<br />

[a..b] and initializes it with the empty priority queue.<br />

3. Operations<br />

b pq item Q.insert(int key, const I& inf )<br />

adds a new item < key, inf > to Q and returns it.<br />

Precondition: key ∈ [a..b]<br />

void<br />

Q.decrease key(b pq item it, int newkey)<br />

makes newkey the new priority of item it.<br />

Precondition: it is an item in Q, newkey ∈ [a..b]<br />

and newkey is not larger than prio(it).<br />

void Q.del item(b pq item x) deletes item it from Q.<br />

Precondition: it is an item in Q.<br />

int Q.prio(b pq item x) returns the priority of item i.<br />

Precondition: it is an item in Q.<br />

const I& Q.inf(b pq item x) returns the information of item i.<br />

Precondition: it is an item in Q.<br />

b pq item Q.find min( ) returns an item with minimal priority (nil if Q is<br />

empty).<br />

I Q.del min( ) deletes the item it = Q.find min( ) from Q and<br />

returns the information of it.<br />

Precondition: Q is not empty.<br />

void Q.clear( ) makes Q the empty bounded prioriy queue.

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

Saved successfully!

Ooh no, something went wrong!