MainExamplesHistoryRecommended Reading
Explain /Computer Science

What is a Queue?

Help others learn from this page

A queue is a data structure that follows First-In-First-Out (FIFO) — like a line at a store. The first person in line is the first person served. New people join at the back, and people leave from the front.

Operations:

  • Enqueue: Add an item to the back (rear)
  • Dequeue: Remove and return the front item
  • Front/Peek: Look at the front item without removing it
  • IsEmpty: Check if the queue is empty

Types:

  • Simple queue: Basic FIFO
  • Priority queue: Items with higher priority go first
  • Circular queue: Wraps around when full
  • Double-ended queue (Deque): Can add/remove from both ends

Common Uses:

  • Task scheduling: Process tasks in order
  • Message queues: Handle messages between services
  • Breadth-first search: Explore graph level by level
  • Print queues: Print documents in order

FAQ

What's the difference between a queue and a stack?
Queue is FIFO (first in, first out). Stack is LIFO (last in, first out).
What's a priority queue?
A queue where items have priorities. Higher priority items are served first, even if they arrived later.

Enjoyed this explanation? Share it!

Promote your content

Reach over 400,000 developers and grow your brand.

Join our developer community

Hang out with over 4,500 developers and share your knowledge.