शब्दकोश · प्रोग्रामिंग

Queue (Data Structure)

A queue is a first-in, first-out data structure where items are added at the back and removed from the front, like a line of people.

अपडेट: अक्टूबर 6, 2026

A queue is a data structure that follows first-in, first-out (FIFO) order: the first item added is the first one removed. Items are enqueued at the back and dequeued from the front, like people waiting in line.

Why it matters

Queues appear wherever work must be processed in arrival order: print jobs, request handling, breadth-first search in graphs and buffering between a fast producer and a slower consumer. In distributed systems, message queues such as RabbitMQ, Amazon SQS and Kafka (a log, with queue-like use) decouple services so a slow task does not block a web request. Variants include the priority queue, which removes the highest-priority item first, and the double-ended queue (deque), which supports both ends.

Example

from collections import deque

jobs = deque()
jobs.append("email-1")
jobs.append("email-2")
jobs.popleft()     # "email-1" comes out first

Using a plain list and pop(0) would shift every element and take O(n) time.

Common mistakes

  • Implementing a queue with an array and removing from the front, which is slow.
  • Letting a queue grow without bound when consumers fall behind.
  • Forgetting that standard message queues may deliver a message more than once.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.