#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. The fundamental queue operations are enqueue (add to back) and dequeue (remove from front).
Constructor
Queue()  O(1) Initializes a new empty queue.
Methods
back()  O(1) Returns the last value in the queue by reference.
clear()  O(1) Removes all elements from the queue.
dequeue()  O(1) Removes and returns the first item in the queue.
enqueue(value)  O(1) Adds value to the end of the queue.
equals(q)  O(N) Returns true if the two queues contain the same elements in the same order.
front()  O(1) Returns the first value in the queue by reference.
isEmpty()  O(1) Returns true if the queue contains no elements.
peek()  O(1) Returns the first value in the queue, without removing it.
size()  O(1) Returns the number of values in the queue.
toString()  O(N) Converts the queue to a printable string representation.
Operators
queue1 == queue1  O(N) Returns true if queue1 and queue2 contain the same elements.
queue1 != queue2  O(N) Returns true if queue1 and queue2 are different.
ostream << queue O(N) Outputs the contents of the queue to the given output stream.
istream >> queue O(N) Reads the contents of the given input stream into the queue.

Constructor detail


Queue();
Initializes a new empty queue.

Usage:

Queue<ValueType> queue;

Method detail


ValueType& back();
Returns the last value in the queue by reference.

If the queue is empty, this function signals an error.

Usage:

ValueType last = queue.back();

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

Usage:

queue.clear();

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

If the queue is empty, this function signals an error.

Usage:

ValueType first = queue.dequeue();

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

Usage:

queue.enqueue(value);

bool equals(const Queue& q) const;
Returns true if the two queues contain exactly the same element values in the same order. Identical in behavior to the == operator.

Usage:

if (q.equals(q2)) ...

ValueType& front();
Returns the first value in the queue by reference.

If the queue is empty, this function signals an error.

Usage:

ValueType first = queue.front();

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

Usage:

if (queue.isEmpty()) ...

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.

If the queue is empty, this function signals an error.

Usage:

ValueType first = queue.peek();

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

Usage:

int n = queue.size();

string toString() const;
Converts the queue to a printable string representation, with the elements listed left-to-right from the front of the queue to the back, such as "{value1, value2, value3}".

Usage:

string str = queue.toString();