#K34642. Circular Buffer Operations
Circular Buffer Operations
Circular Buffer Operations
You are given the task of simulating a circular buffer which stores entries consisting of a timestamp and a packet size. The buffer supports three operations:
- ADD timestamp packet_size: Add an entry to the buffer. If the buffer is full, the oldest entry is overwritten.
- REMOVE timestamp: Remove all entries in the buffer that have the given timestamp.
- PRINT: Print all entries in the buffer in the order they were added. If the buffer is empty, print "EMPTY".
The buffer behaves in a circular manner. That is, when an ADD operation is executed on a full buffer, the new entry overwrites the oldest entry. Your program should simulate these operations based on the input provided.
inputFormat
The first line of input contains two integers n and m where:
- n is the capacity of the circular buffer.
- m is the number of operations.
The next m lines each contain one of the operations in one of the following formats:
ADD timestamp packet_size
REMOVE timestamp
PRINT
outputFormat
For every PRINT
operation, output each entry in the buffer on a new line in the format timestamp packet_size
. If the buffer is empty during a PRINT
operation, output a single line containing EMPTY
.
3 5
ADD 1 100
ADD 2 150
ADD 3 200
ADD 4 250
PRINT
2 150
3 200
4 250
</p>