Return to Index

Queue

A templated queue collection class. The queue is implemented as singly-linked list, and can be traversed from the front to the rear using the first() / next() methods. The queue can only store pointers to objects. Therefore, the declaration
   Queue‹ SomeClass › my_queue;
declares a list of pointers of type SomeClass. Then, a traversal is of the following form:
   SomeClass *ptr = my_queue.first();
   while (ptr) {
     ...
     ptr = my_queue.next();
   }

Elements are added and removed from the queue using the standard enqueue() and dequeue() methods.


Method Summary:
Queue::Queue();
void Queue::setAutoDelete(bool b);
void Queue::clear();
int Queue::length();
int Queue::itemCount();
type* Queue::first();
type* Queue::next();
void Queue::enqueue(type* data);
type* Queue::dequeue();
void Queue::pushBack(type* data);
type* Queue::peek();
bool Queue::isEmpty();



Queue::Queue
Queue::Queue();

Creates a new queue class.

void Queue::setAutoDelete
void Queue::setAutoDelete(bool b);

or when the the list itself is deleted.
Parameters:
bool bEnable or disable auto-deletion.

void Queue::clear
void Queue::clear();

Empties the queue, deleting any objects if auto-deletion is enabled.

int Queue::length
int Queue::length();

Returns the length of the queue. This is equivalent to itemCount().

int Queue::itemCount
int Queue::itemCount();

Returns the length of the queue. This is equivalent to length() .

type* Queue::first
type* Queue::first();

Returns the first object in the queue.

type* Queue::next
type* Queue::next();

Returns the next object in the queue.

void Queue::enqueue
void Queue::enqueue(type* data);

Enqueues an object to the end of the queue.
Parameters:
type* dataA pointer to an instance of the appropriate object type.

type* Queue::dequeue
type* Queue::dequeue();

Removes the first item on the queue and returns it.

Returns: If the queue is empty, NULL is returned.

void Queue::pushBack
void Queue::pushBack(type* data);

Pushes an element back into the queue, but at the front. This essentially undoes the dequeue() operation.
Parameters:
type* dataA pointer to an instance of the appropriate object type.

type* Queue::peek
type* Queue::peek();

Returns the first object on the queue without removing it.

Returns: NULL is returned if the queue is empty.

bool Queue::isEmpty
bool Queue::isEmpty();

Determines whether the queue has items in it.


Generated automatically by docgen 0.0.1
© 2003 Aron Dobos