What is a Queue?

This lesson defines the queue as an abstract data type, explains FIFO (first-in, first-out), introduces enqueue, dequeue, and peek/front, and contrasts a queue with a stack. Later pages cover implementations in C, queue types, and algorithmic applications.

On this page
  • What is a queue? — FIFO mental model
  • Core operations: enqueue, dequeue, peek/front
  • Overflow, underflow, and empty queue
  • Queue vs stack — quick comparison
  • Where queues appear in practice — next lessons

1) What is a queue?

A queue is a linear collection where elements are inserted at one end and removed from the other. New items enter at the rear, and existing items leave from the front. This rule gives first-in, first-out (FIFO) behavior.

Think of people waiting at a ticket counter: the person who arrives first is served first. You do not skip to the middle when removing. That order guarantee is why queues are used for scheduling and buffering.

Schematic: rear inserts, front removes

After enqueueing A, then B, then C:

front → [ A ] [ B ] [ C ] ← rear
dequeue removes A first; enqueue adds after C

2) Core operations

  • Enqueue — Insert an element at the rear. On a full array-based queue, enqueue can cause overflow if capacity is fixed.
  • Dequeue — Remove and return the front element. Dequeue from an empty queue is underflow (an error state you must avoid in C).
  • Peek / Front — Read the front value without removing it. Useful when you need to inspect the next item to be processed.

Exact names vary (enqueue, dequeue, front, rear, isEmpty, isFull); the ideas stay the same.

3) Queue vs stack

Both are linear ADTs with restricted access, but their removal order differs:

ADT Order Insert Remove
Queue FIFO At rear From front
Stack LIFO (last-in, first-out) At top From top

4) Where queues show up

Queues model anything processed in arrival order: printer job queues, task scheduling, request buffering, CPU/job dispatch, and graph traversals like BFS. This tutorial’s next pages walk through terminology, implementations (array and linked list), queue types, and problem-solving patterns in C.

Key takeaway

A queue is a FIFO line: insert at the rear, remove from the front. Master enqueue, dequeue, and front/peek, and always guard empty and full conditions in C.

Next up: Queue terminology · Characteristics of Queue (FIFO) · Basic queue operations