Practice

Circular Queue Enqueue and Dequeue

2023/Oct/Nov·Variant 2
HARDQueues

Implement a circular queue of up to 4 strings using array QueueData, with Head, Tail and a Count of items currently stored (Count avoids the usual ambiguity of Head = Tail meaning both empty and full).

Write:

  • function Enqueue(Value) — insert at Tail, wrapping around with MOD, and return TRUE; return FALSE if the queue is full
  • function Dequeue() — remove from Head, wrapping around with MOD, and return the removed value; return "false" if the queue is empty

Input: An operation count, then operations. E is followed by a value to enqueue; D dequeues. Output: One result per operation.

Example:

Input:  1
        D
Output: false
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Interleaved enqueue and dequeue
Inputs: 6, E, A, E, B, D, E, C, E, Q, D
Expected: TRUE TRUE A TRUE TRUE B
Test 2: Dequeue when empty
Inputs: 1, D
Expected: false