The SimpleCxxLib package


#include "queue.h"

class Queue<ValueType>

This class models a linear structure called a queue in which values are added at one end and removed from the other. This discipline gives rise to a first-in/first-out behavior (FIFO) that is the defining feature of queues.
Constructor
Queue() Initializes a new empty queue.
Methods
clear() Removes all elements from the queue.
dequeue() Removes and returns the first item in the queue.
enqueue(value) Adds value to the end of the queue.
isEmpty() Returns true if the queue contains no elements.
peek() Returns the first value in the queue, without removing it.
size() Returns the number of values in the queue.
toString() Converts the queue to a printable string representation.

Constructor detail


Queue();
Initializes a new empty queue.

Usage:

Queue<ValueType> queue;
Queue<ValueType> queue = { frontValue, middleValue, backValue };

Method detail


int size() const;
Returns the number of values in the queue.

Usage:

int n = queue.size();

bool isEmpty() const;
Returns true if the queue contains no elements.

Usage:

if (queue.isEmpty()) ...

void clear();
Removes all elements from the queue.

Usage:

queue.clear();

void enqueue(ValueType value);
Adds value to the end of the queue.

Usage:

queue.enqueue(value);

ValueType dequeue();
Removes and returns the first item in the queue.

Usage:

ValueType first = queue.dequeue();

ValueType peek() const;
Returns the first value in the queue, without removing it. For compatibility with the STL classes, this method is also exported under the name front, in which case it returns the value by reference.

Usage:

ValueType first = queue.peek();

string toString();
Converts the queue to a printable string representation.

Usage:

string str = queue.toString();