ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.5 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | PASS | meta_canonical IS NULL OR = '' OR = src_unparsed | Not set |
| Property | Value |
|---|---|
| URL | https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue |
| Last Crawled | 2026-03-23 09:02:18 (14 days ago) |
| First Indexed | not set |
| HTTP Status Code | 200 |
| Meta Title | Queue |
| Meta Description | null |
| Meta Canonical | null |
| Boilerpipe Text | #include "queue.h"
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). 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
Queue()
O(1)
Initializes a new empty queue.
Methods
clear()
O(N)
Removes all elements from the queue.
dequeue()
O(1)
Removes and returns the frontmost element in the queue.
enqueue(
value
)
O(1)
Adds
value
to the back of the queue.
equals(
q
)
O(N)
Returns
true
if the two queues contain the same elements in the same order.
isEmpty()
O(1)
Returns
true
if the queue contains no elements.
peek()
O(1)
Returns the frontmost element in the queue, without removing it.
size()
O(1)
Returns the number of values in the queue.
toString()
O(N)
Returns a printable string representation of this queue.
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. You may also optionally provide an initializer
list of values. The newly created queue will contain those values listed left-to-right
in order from front of the queue to the back.
Usage:
Queue<ValueType> queue;
Queue<ValueType> queue = { frontValue, middleValue, backValue };
Method detail
void clear();
Removes all elements from the queue.
Usage:
queue.clear();
ValueType dequeue();
Removes and returns the frontmost element in the queue. If the queue is empty, this function signals an error.
Usage:
ValueType first = queue.dequeue();
void enqueue(const ValueType& value);
Adds
value
to the back of the queue.
Usage:
queue.enqueue(value);
bool equals(const Queue& queue) const;
Returns
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;
Returns
true
if the queue contains no elements.
Usage:
if (queue.isEmpty()) ...
const ValueType& peek() const;
Returns the frontmost element in the queue, without removing it. 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;
Returns a printable string representation of this queue. The elements are listed left-to-right from the front of the queue to the back, such as
"{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
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) ... |
| Markdown | | | |
|---|---|
|  | The Stanford `libcs106` library, Academic Year 2025-26 |
***
\#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). 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 | | |
| [Queue()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Constructor:Queue) | O(1) | Initializes a new empty queue. |
| Methods | | |
| [clear()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:clear) | O(N) | Removes all elements from the queue. |
| [dequeue()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:dequeue) | O(1) | Removes and returns the frontmost element in the queue. |
| [enqueue(value)](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:enqueue) | O(1) | Adds `value` to the back of the queue. |
| [equals(q)](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:equals) | O(N) | Returns `true` if the two queues contain the same elements in the same order. |
| [isEmpty()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:isEmpty) | O(1) | Returns `true` if the queue contains no elements. |
| [peek()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:peek) | O(1) | Returns the frontmost element in the queue, without removing it. |
| [size()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:size) | O(1) | Returns the number of values in the queue. |
| [toString()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:toString) | O(N) | Returns a printable string representation of this queue. |
| Operators | | |
| [queue1 == queue1](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:==) | O(N) | Returns `true` if `queue1` and `queue2` contain the same elements. |
| [queue1 != queue2](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:!=) | O(N) | Returns `true` if `queue1` and `queue2` are different. |
| [ostream \<\< queue](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:<<) | O(N) | Outputs the contents of the queue to the given output stream. |
| [istream \>\> queue](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:>>) | O(N) | Reads the contents of the given input stream into the queue. |
## Constructor detail
***
```
Queue();
```
Initializes a new empty queue. You may also optionally provide an initializer list of values. The newly created queue will contain those values listed left-to-right in order from front of the queue to the back.
Usage:
```
Queue<ValueType> queue;
Queue<ValueType> queue = { frontValue, middleValue, backValue };
```
***
## Method detail
***
```
void clear();
```
Removes all elements from the queue.
Usage:
```
queue.clear();
```
***
```
ValueType dequeue();
```
Removes and returns the frontmost element in the queue. If the queue is empty, this function signals an error.
Usage:
```
ValueType first = queue.dequeue();
```
***
```
void enqueue(const ValueType& value);
```
Adds `value` to the back of the queue.
Usage:
```
queue.enqueue(value);
```
***
```
bool equals(const Queue& queue) const;
```
Returns `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;
```
Returns `true` if the queue contains no elements.
Usage:
```
if (queue.isEmpty()) ...
```
***
```
const ValueType& peek() const;
```
Returns the frontmost element in the queue, without removing it. 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;
```
Returns a printable string representation of this queue. The elements are listed left-to-right from the front of the queue to the back, such as `"{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
``` |
| Readable Markdown | ***
\#include "queue.h"
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). 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 | | |
| [Queue()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Constructor:Queue) | O(1) | Initializes a new empty queue. |
| Methods | | |
| [clear()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:clear) | O(N) | Removes all elements from the queue. |
| [dequeue()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:dequeue) | O(1) | Removes and returns the frontmost element in the queue. |
| [enqueue(value)](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:enqueue) | O(1) | Adds `value` to the back of the queue. |
| [equals(q)](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:equals) | O(N) | Returns `true` if the two queues contain the same elements in the same order. |
| [isEmpty()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:isEmpty) | O(1) | Returns `true` if the queue contains no elements. |
| [peek()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:peek) | O(1) | Returns the frontmost element in the queue, without removing it. |
| [size()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:size) | O(1) | Returns the number of values in the queue. |
| [toString()](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Method:toString) | O(N) | Returns a printable string representation of this queue. |
| Operators | | |
| [queue1 == queue1](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:==) | O(N) | Returns `true` if `queue1` and `queue2` contain the same elements. |
| [queue1 != queue2](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:!=) | O(N) | Returns `true` if `queue1` and `queue2` are different. |
| [ostream \<\< queue](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:<<) | O(N) | Outputs the contents of the queue to the given output stream. |
| [istream \>\> queue](https://web.stanford.edu/dept/cs_edu/resources/cslib_docs/Queue#Operator:>>) | O(N) | Reads the contents of the given input stream into the queue. |
## Constructor detail
***
```
Queue();
```
Initializes a new empty queue. You may also optionally provide an initializer list of values. The newly created queue will contain those values listed left-to-right in order from front of the queue to the back.
Usage:
```
Queue<ValueType> queue;
Queue<ValueType> queue = { frontValue, middleValue, backValue };
```
***
## Method detail
***
```
void clear();
```
Removes all elements from the queue.
Usage:
```
queue.clear();
```
***
```
ValueType dequeue();
```
Removes and returns the frontmost element in the queue. If the queue is empty, this function signals an error.
Usage:
```
ValueType first = queue.dequeue();
```
***
```
void enqueue(const ValueType& value);
```
Adds `value` to the back of the queue.
Usage:
```
queue.enqueue(value);
```
***
```
bool equals(const Queue& queue) const;
```
Returns `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;
```
Returns `true` if the queue contains no elements.
Usage:
```
if (queue.isEmpty()) ...
```
***
```
const ValueType& peek() const;
```
Returns the frontmost element in the queue, without removing it. 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;
```
Returns a printable string representation of this queue. The elements are listed left-to-right from the front of the queue to the back, such as `"{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
``` |
| Shard | 31 (laksa) |
| Root Hash | 9619766982384267031 |
| Unparsed URL | edu,stanford!web,/dept/cs_edu/resources/cslib_docs/Queue s443 |