---
title: "Queues: First In, First Out"
description: "A collection where values leave in the order they arrived: enqueue at the back, dequeue at the front. The circular queue keeps the front from drifting off the end of the storage."
canonical: https://lightmysky.com/learn/computing/queues-first-in-first-out-mt_4U1bT0JW4g
source: https://lightmysky.com/learn/computing/queues-first-in-first-out-mt_4U1bT0JW4g.md
retrieved: 2026-09-12
---

> **Agent view.** This is the Markdown twin of the page, for tools and assistants.
> When to use this site, and the call that answers each job: https://lightmysky.com/agent-instructions.md
> API description (OpenAPI 3.1): https://lightmysky.com/openapi.json · Authentication: https://lightmysky.com/auth.md
> Pricing: https://lightmysky.com/pricing.md · Catalog: https://lightmysky.com/llms.txt · Full catalog: https://lightmysky.com/llms-full.txt
> Every machine-readable file on this domain: https://lightmysky.com/.well-known/ai-catalog.json
> Ask for Markdown with `Accept: text/markdown`, a `.md` address, or `?mode=agent`.

# Queues: First In, First Out

A collection where values leave in the order they arrived: enqueue at the back, dequeue at the front. The circular queue keeps the front from drifting off the end of the storage.

Subject: Computing · Area: Algorithms & Data Structures · Ages 16 to 18
Page: https://lightmysky.com/learn/computing/queues-first-in-first-out-mt_4U1bT0JW4g

## Ready when they can

- Trace a queue through a run of enqueue and dequeue operations
- Give the order the same four values come back out of a queue and out of a stack
- Explain why a print spooler or a network buffer needs arrival order kept

## Lesson: The line with no overtaking

A queue is a line you join at the back and leave from the front. Enqueue adds an item at the rear and dequeue removes the item at the front, so the first thing in is always the first thing out. That is the whole rule: first in, first out, no overtaking allowed.

**Example.** To trace a queue, write the line left to right after every operation and cross off from the front only. Try it: enqueue 4, enqueue 7, dequeue, enqueue 9 leaves 7 at the front with 9 behind. Run the same four values through a stack and through a queue and the outputs come back in opposite orders. Dequeueing an empty queue is an error. An editor undo needs newest first, so it uses a stack, not a queue.

A print spooler is a queue: several people send documents at once but the printer prints one page at a time. Each document enqueues at the back and the printer dequeues from the front, so jobs print in arrival order and nobody jumps ahead. When a front job jams, everything behind it waits: cancel the stuck job or restart the spooler and the line flows again in order. Network buffers work the same way, holding bursts so nothing is lost or reordered.

In Python a list can act as a small queue. Removing from the front shifts everything else along, which is fine for learning but slow for huge lines, and that cost is why real programs use a dedicated double ended queue. For tracing by hand, the list version is fine.

**Recap.** First in, first out: join at the back, leave from the front.

## Practice

8 questions on this page, each with its working shown.

## Needs first

- [Stacks: Last In, First Out](https://lightmysky.com/learn/computing/stacks-last-in-first-out-mt_Evw7zeJE6Q)

## Opens up

- [Linked Lists and Nodes That Point](https://lightmysky.com/learn/computing/linked-lists-and-nodes-that-point-mt_HvY7_-M2Zj)
- [Breadth-First and Depth-First Search](https://lightmysky.com/learn/computing/breadth-first-and-depth-first-search-mt_q8IEzoBhzy)
- [Scheduling: Deciding Which Process Runs Next](https://lightmysky.com/learn/computing/scheduling-deciding-which-process-runs-next-mt_QZYzfVIcP6)
- [Message Passing and Asynchronous Work](https://lightmysky.com/learn/computing/message-passing-and-asynchronous-work-mt_twcpO-945r)
- [Heaps and Priority Queues](https://lightmysky.com/learn/computing/heaps-and-priority-queues-mt_W-ofiMiXWs)
