Circular queue · Compiler

Circular queue

Simulate a packet buffer with c slots numbered 0 through c - 1. Both the front and the next write slot start at 0. PUT x writes at the next write slot and advances that index. TAKE removes the front packet and advances the front index. Each index wraps from c - 1 to 0 and keeps its position when the buffer drains. A PUT on a full buffer or a TAKE on an empty buffer leaves the buffer and both indices unchanged.

Input
The first line contains c and q (1 <= c <= 50, 1 <= q <= 100). Each of the next q lines contains PUT x or TAKE, where packet ID x is an integer from 1 to 1000.
Output
Print one line per command. For PUT print the slot written, or FULL if the buffer is full. For TAKE print the ID removed, or EMPTY if the buffer is empty.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…