Analogy: People in a Line

Think of a queue at:
  • A bus stop
  • A ticket counter
  • A fast food restaurant
The first person to arrive is the first to be served, and new people join at the end of the line. In a queue data structure, the first element added is the first one to be removed. That’s how a queue works in programming too. Queue Pn The main operations on a queue are:
  • Enqueue: Adds an element to the back (or “rear”) of the queue.
  • Dequeue: Removes the element from the front of the queue.
from collections import deque

# Create an empty queue
queue = deque()

# Enqueue (add to end)
queue.append("Task 1")
queue.append("Task 2")
queue.append("Task 3")

print("Queue:", queue)

# Dequeue (remove from front)
first_task = queue.popleft()
print("Dequeued:", first_task)
print("Queue after dequeue:", queue)
Use Case
Print QueueDocuments are printed in the order they were added
Task SchedulingOS or threads manage jobs/tasks using queues
Call Center SystemsIncoming calls are held in a queue
Data StreamingReal-time processing of messages/events
Keyboard/Input BuffersCharacters typed by users are stored and processed in order
https://en.wikipedia.org/wiki/Queue_(abstract_data_type)