Practice

Linear Queue Operations

2024/May/June·Variant 1·Q3
HARDQueues

Adapted from Cambridge International AS & A Level Computer Science (9618), May/June 2024 Paper 41, Question 3.

A linear queue stores up to 20 strings in QueueData. QueueHead and QueueTail both start at -1.

Write:

  • function Enqueue(DataToInsert) to insert data if the queue is not full and return TRUE; return FALSE if the queue is full
  • function Dequeue() to return "false" if the queue is empty, otherwise return the next item and update the head pointer

The test harness reads a number of operations. Operation E is followed by a value and must output the result of Enqueue(). Operation D must output the result of Dequeue().

Input: Operation count, then operations. Output: One line per operation result.

Example:

Input:  5
        E
        A
        E
        B
        D
        D
        D
Output: TRUE
        TRUE
        A
        B
        false
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Enqueue two, dequeue three
Inputs: 5, E, A, E, B, D, D, D
Expected: TRUE TRUE A B false
Test 2: Empty dequeue before insert
Inputs: 3, D, E, Oak, D
Expected: false TRUE Oak