#include "deque.h"

class Deque<ValueType>

This file exports the Deque class, an ordered collection with a front and back in which elements can be efficiently added and removed from both the front and the back. A deque combines many of the benefits of a stack and a queue.
Constructor
Deque()  O(1) Initializes a new empty deque.
Methods
add(value)  O(1) Adds a value to the back of the deque; equivalent to addBack.
addBack(value)  O(1) Adds a value to the back of the deque.
addFront(value)  O(1) Adds a value to the front of the deque.
back()  O(1) Returns the last value in the deque by reference.
clear()  O(N) Removes all elements from the deque.
dequeue(value)  O(1) Removes a value from the front of the deque; equivalent to dequeueFront.
dequeueBack(value)  O(1) Removes a value from the back of the deque.
dequeueFront(value)  O(1) Removes a value from the front of the deque.
enqueue(value)  O(1) Adds a value to the end of the deque; equivalent to enqueueBack.
enqueueBack(value)  O(1) Adds a value to the end of the deque.
enqueueFront(value)  O(1) Adds a value to the front of the deque.
equals(deque)  O(N) Returns true if the two deques contain the same elements in the same order.
front()  O(1) Returns the first value in the deque by reference.
isEmpty()  O(1) Returns true if the deque contains no elements.
peek()  O(1) Returns the first value in the deque, without removing it; equivalent to peekFront.
peekBack()  O(1) Returns the last value in the deque, without removing it.
peekFront()  O(1) Returns the first value in the deque, without removing it.
remove(value)  O(1) Removes a value from the front of the deque; equivalent to removeFront or dequeueFront.
removeBack(value)  O(1) Removes a value from the back of the deque.
removeFront(value)  O(1) Removes a value from the front of the deque.
size()  O(1) Returns the number of values in the deque.
toString()  O(N) Converts the deque to a printable string representation.
Operators
deque1 == deque1  O(N) Returns true if deque1 and deque2 contain the same elements.
deque1 != deque2  O(N) Returns true if deque1 and deque2 are different.
ostream << deque O(N) Outputs the contents of the deque to the given output stream.
istream >> deque O(N) Reads the contents of the given input stream into the deque.

Constructor detail


Deque();
Initializes a new empty deque.

Usage:

Deque<ValueType> deque;

Method detail


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

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

Usage:

ValueType last = deque.back();

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

Usage:

deque.clear();

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

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

Usage:

ValueType first = deque.dequeue();

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

Usage:

deque.enqueue(value);

bool equals(const Deque& q) const;
Returns true if the two deques 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 deque by reference.

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

Usage:

ValueType first = deque.front();

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

Usage:

if (deque.isEmpty()) ...

ValueType peek() const;
Returns the first value in the deque, 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 deque is empty, this function signals an error.

Usage:

ValueType first = deque.peek();

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

Usage:

int n = deque.size();

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

Usage:

string str = deque.toString();