class Deque<ValueType>
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 | ||
O(1) | Initializes a new empty deque. | |
Methods | ||
O(1) | Adds a value to the back of the deque; equivalent to addBack . |
|
O(1) | Adds a value to the back of the deque. | |
O(1) | Adds a value to the front of the deque. | |
O(1) | Returns the last value in the deque by reference. | |
O(N) | Removes all elements from the deque. | |
O(1) | Removes a value from the front of the deque; equivalent to dequeueFront . |
|
O(1) | Removes a value from the back of the deque. | |
O(1) | Removes a value from the front of the deque. | |
O(1) | Adds a value to the end of the deque; equivalent to enqueueBack . |
|
O(1) | Adds a value to the end of the deque. | |
O(1) | Adds a value to the front of the deque. | |
O(N) | Returns true if the two deques contain the same elements in the same order. |
|
O(1) | Returns the first value in the deque by reference. | |
O(1) | Returns true if the deque contains no elements. |
|
O(1) | Returns the first value in the deque, without removing it; equivalent to peekFront . |
|
O(1) | Returns the last value in the deque, without removing it. | |
O(1) | Returns the first value in the deque, without removing it. | |
O(1) | Removes a value from the front of the deque; equivalent to removeFront or dequeueFront . |
|
O(1) | Removes a value from the back of the deque. | |
O(1) | Removes a value from the front of the deque. | |
O(1) | Returns the number of values in the deque. | |
O(N) | Converts the deque to a printable string representation. | |
Operators | ||
O(N) | Returns true if deque1 and deque2 contain the same elements. |
|
O(N) | Returns true if deque1 and deque2 are different. |
|
O(N) | Outputs the contents of the deque to the given output stream. | |
O(N) | Reads the contents of the given input stream into the deque. |
Deque();
Usage:
Deque<ValueType> deque;
ValueType& back();
If the deque is empty, this function signals an error.
Usage:
ValueType last = deque.back();
void clear();
Usage:
deque.clear();
ValueType dequeue();
If the deque is empty, this function signals an error.
Usage:
ValueType first = deque.dequeue();
void enqueue(ValueType value);
value
to the end of the deque.
Usage:
deque.enqueue(value);
bool equals(const Deque& q) const;
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();
If the deque is empty, this function signals an error.
Usage:
ValueType first = deque.front();
bool isEmpty() const;
true
if the deque contains no elements.
Usage:
if (deque.isEmpty()) ...
ValueType peek() const;
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;
Usage:
int n = deque.size();
string toString() const;
"{value1, value2, value3}"
.
Usage:
string str = deque.toString();