Queue Mastery

Cambridge International AS & A Level Computer Science 9618

Mastering Queues

An interactive deep-dive into linear and circular queues — from abstract data types to array implementations.

Linear Queue

Theory, diagrams, and interactive simulator for linear queues implemented in a 1D array.

0%

Circular Queue

MOD wrap-around, trace tool, and interactive simulator for circular queues.

0%

Exam Prep

10 Cambridge-style written questions with AI-powered feedback on accuracy, terminology, and depth.

0%

What is an Abstract Data Type (ADT)?

Definition

An Abstract Data Type (ADT) is a collection of data together with a set of operations that can be performed on that data. The ADT defines what operations are available, but not how they are implemented.

Think of an ADT like a vending machine: you know what buttons to press (operations) and what you get out (results), but you don't need to know the internal mechanics.

Key ADTs for 9618

  • Stack — Last In, First Out (LIFO)
  • Queue — First In, First Out (FIFO) — our focus
  • Linked List — Dynamic sequential collection
Queue ADT

Data

An ordered collection of elements

Operations

Enqueue Dequeue Peek / Front IsEmpty IsFull

The Queue ADT separates interface from implementation.

Real-World Queue Examples

Print Queue

Documents printed in the order sent to the printer.

Call Centre

Callers served in the order they joined the line.

Keyboard Buffer

Keystrokes processed in the order typed.

Web Server

HTTP requests handled first-come, first-served.

Why Use a Queue?

SituationWhy a Queue?Why Not a Stack?
Processing tasks in arrival orderFIFO preserves fairnessLIFO would process newest first
Buffering data between processesMaintains original sequenceWould reverse the sequence
Breadth-first graph traversalExplores level by levelWould give depth-first traversal
Explore Linear Queues Explore Circular Queues

Code Lab

Java implementations of linear and circular queues using 1D arrays.

Java Implementation

public class LinearQueue {
    private String[] queue;
    private int front, rear, maxSize;

    public LinearQueue(int size) {
        maxSize = size;
        queue = new String[maxSize];
        front = 0;  rear = -1;
    }

    public void enqueue(String item) {
        if (rear >= maxSize - 1) {
            System.out.println("Queue is full");
        } else {
            rear++;
            queue[rear] = item;
        }
    }

    public String dequeue() {
        if (front > rear) {
            System.out.println("Queue is empty");
            return "";
        }
        String item = queue[front];
        front++;
        return item;
    }

    public boolean isEmpty() { return front > rear; }
    public boolean isFull()  { return rear >= maxSize - 1; }
}

Code Annotation Challenge

Click on each line to reveal what it does.

rear = (rear + 1) % maxSize;
queue[rear] = item;
size = size + 1;
String item = queue[front];
front = (front + 1) % maxSize;
if (size >= maxSize)

Parsons Problems

Drag the lines of code into the correct order to build working queue operations.

Arrange the pseudocode lines in the correct order for a linear queue enqueue operation.

Available Lines

Your Solution

Knowledge Check

Test your understanding. Receive adaptive feedback on every question.

Question 1 of 12Score: 0

Exam Prep

Cambridge 9618-style written questions. Type your answer and receive targeted feedback on accuracy, terminology, and depth of understanding.

Ref