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