#K3621. Bounded Queue Simulation
Bounded Queue Simulation
Bounded Queue Simulation
You are required to simulate operations on a bounded queue data structure. The queue has a maximum size \( M \) (denoted as max_size
). Your program must support the following operations:
enqueue X
: Add an integer \( X \) to the end of the queue. If the queue is already full (i.e. its current size equals \( M \)), output "ERROR".dequeue
: Remove the integer at the front of the queue. If the queue is empty, output "ERROR". Note that a successfuldequeue
does not produce any output.get_front
: Output the integer at the front of the queue without removing it. If the queue is empty, output "ERROR".get_size
: Output the current number of elements in the queue.is_empty
: Output "true" if the queue is empty; otherwise, output "false".
The input begins with two integers, \( N \) and \( M \), representing the number of operations and the maximum allowed capacity of the queue respectively. The next \( N \) lines each contain one of the operations described above.
Note: Only operations that are supposed to produce outputs (i.e. error conditions or explicit output commands) will result in printed lines. For instance, a successful enqueue
or dequeue
does not produce any output.
inputFormat
The first line of input contains two integers \( N \) and \( M \) separated by a space, where \( N \) is the total number of operations and \( M \) is the maximum capacity of the queue. The following \( N \) lines each contain a command. The commands are one of the following formats:
enqueue X
where \( X \) is an integer.dequeue
get_front
get_size
is_empty
outputFormat
For each operation that produces output, print the result on a separate line. The expected outputs are as follows:
get_front
: Prints the element at the front of the queue or "ERROR" if the queue is empty.get_size
: Prints the current size of the queue.is_empty
: Prints "true" if the queue is empty or "false" otherwise.enqueue
anddequeue
: Only print "ERROR" if the operation fails (i.e. enqueue when full or dequeue when empty).
10 5
enqueue 1
enqueue 2
get_front
get_size
dequeue
get_front
get_size
dequeue
dequeue
is_empty
1
2
2
1
ERROR
true
</p>