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.

6.4 Queues ( queue )<br />

1. Definition<br />

An instance Q of the parameterized data type queue is a sequence of elements of data<br />

type E, called the element type of Q. Elements are inserted at one end (the rear) and<br />

deleted at the other end (the front) of Q. <strong>The</strong> size of Q is the length of the sequence; a<br />

queue of size zero is called the empty queue.<br />

#include < <strong>LEDA</strong>/core/queue.h ><br />

2. Types<br />

queue:: value type<br />

the value type.<br />

3. Creation<br />

queue Q;<br />

creates an instance Q of type queue. Q is initialized with<br />

the empty queue.<br />

4. Operations<br />

const E& Q.top( ) returns the front element of Q.<br />

Precondition: Q is not empty.<br />

const E& Q.pop( ) deletes and returns the front element of Q.<br />

Precondition: Q is not empty.<br />

void Q.append(const E& x)<br />

appends x to the rear end of Q.<br />

int Q.size( ) returns the size of Q.<br />

bool Q.empty( ) returns true if Q is empty, false otherwise.<br />

void Q.clear( ) makes Q the empty queue.<br />

5. Implementation<br />

Queues are implemented by singly linked linear lists. All operations take time O(1),<br />

except clear which takes time O(n), where n is the size of the queue.

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

Saved successfully!

Ooh no, something went wrong!