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!
Last Week in Plain English
Stay updated with the latest news in the world of AI, tech, business, and startups.
Interested in Promoting Your Content?
Reach our engaged developer audience and grow your brand.
Help us expand the developer universe!
This is your chance to be part of an amazing community built by developers, for developers.