class Queue<ValueType>
enqueue
(add to back)
and dequeue
(remove from front). Both of these operations run in O(1) time.
Queues do not allow access to elements by index, nor can you iterate through the elements using the range-based for loop.
Constructor | ||
O(1) | Initializes a new empty queue. | |
Methods | ||
O(N) | Removes all elements from the queue. | |
O(1) | Removes and returns the frontmost element in the queue. | |
O(1) | Adds value to the back of the queue. |
|
O(N) | Returns true if the two queues contain the same elements in the same order. |
|
O(1) | Returns true if the queue contains no elements. |
|
O(1) | Returns the frontmost element in the queue, without removing it. | |
O(1) | Returns the number of values in the queue. | |
O(N) | Returns a printable string representation of this queue. | |
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; Queue<ValueType> queue = { frontValue, middleValue, backValue };
void clear();
Usage:
queue.clear();
ValueType dequeue();
Usage:
ValueType first = queue.dequeue();
void enqueue(const ValueType& value);
value
to the back of the queue.
Usage:
queue.enqueue(value);
bool equals(const Queue& queue) const;
true
if the two queues contain exactly the same values in the same order.
Identical in behavior to the ==
operator.
Usage:
if (queue1.equals(queue2)) ...
bool isEmpty() const;
true
if the queue contains no elements.
Usage:
if (queue.isEmpty()) ...
const ValueType& peek() const;
Usage:
ValueType first = queue.peek();
int size() const;
Usage:
int n = queue.size();
string toString() const;
"{value1, value2, value3}"
.
Usage:
string str = queue.toString();
ostream& operator<<(const Queue& queue);Outputs the contents of
queue
to the given output stream.
The output is in the form {value1, value2, value3}
where elements are listed left-to-right from the front of the queue to the back.
Usage:
cout << queue << endl;
istream& operator>>(Queue& queue);Reads the contents of the given input stream into
queue
. Any previous
contents of the queue are replaced.
The input is expected to be in the form {value1, value2, value3}
where elements are listed left-to-right from the front of the queue to the back. If unable to read a proper
queue from the stream, the operation results in a stream fail state.
Usage:
if (infile >> queue) ...