Linear Queue

The simplest queue implementation — elements enter at the rear and leave from the front, stored in a one-dimensional array.

How a Linear Queue Works

Key Pointers

  • Front — points to the first element (next to be removed)
  • Rear — points to the last element (most recently added)

Operations

Enqueue Add to rear

  1. Check if the queue is full (rear = MaxSize - 1)
  2. Increment rear pointer by 1
  3. Place the new item at queue[rear]

Dequeue Remove from front

  1. Check if the queue is empty (front > rear)
  2. Retrieve item at queue[front]
  3. Increment front pointer by 1

The Problem with Linear Queues

Once the rear pointer reaches the end of the array, no more items can be added — even if spaces at the front have been freed by dequeue operations. This wasted space is the main limitation.

Initial State (Empty Queue, Size 6)

Front = 0Rear = -1
0
1
2
3
4
5

After Enqueue(A), Enqueue(B), Enqueue(C)

Front = 0Rear = 2
A0
B1
C2
3
4
5

After Dequeue() — returns A

Front = 1Rear = 2
0
B1
C2
3
4
5

Index 0 is now wasted space — it cannot be reused in a linear queue.

Interactive Linear Queue Simulator

Try enqueue and dequeue operations yourself. Watch the front and rear pointers move.

Front: 0 Rear: -1 Size: 0
Queue initialised. Front = 0, Rear = -1.

Linear Queue — Pseudocode (9618 Style)

PROCEDURE Enqueue(Queue, Rear, MaxSize, Item)
    IF Rear >= MaxSize - 1 THEN
        OUTPUT "Queue is full"
    ELSE
        Rear ← Rear + 1
        Queue[Rear] ← Item
    ENDIF
ENDPROCEDURE
Home Next: Circular Queue