#B3616. Implementing a Custom Queue with Basic Operations
Implementing a Custom Queue with Basic Operations
Implementing a Custom Queue with Basic Operations
You are required to implement a queue data structure supporting the following operations:
push(x)
: Insert a number \(x\) into the queue.pop()
: Remove the front element from the queue. If the queue is empty, do not remove any element and outputERR_CANNOT_POP
.query()
: Output the front element of the queue. If the queue is empty, outputERR_CANNOT_QUERY
.size()
: Output the current number of elements in the queue.
The commands will be provided in the input. The first line of the input contains an integer representing the number of operations. Each of the following lines contains one of the above commands. Note that the operations push
do not produce any output, while pop
, query
, and size
may result in printed output (if applicable).
inputFormat
The input consists of multiple lines.
- The first line contains an integer \(n\) representing the number of operations.
- The next \(n\) lines each contain a command, which can be one of the following:
push x
where \(x\) is an integer.pop
query
size
outputFormat
For each command that produces an output (pop
when the queue is empty, query
, and size
), output the corresponding result on a new line.
If a pop
command is executed on an empty queue, output ERR_CANNOT_POP
.
If a query
command is executed on an empty queue, output ERR_CANNOT_QUERY
.
sample
5
push 10
push 20
query
pop
query
10
20
</p>