Types of Queue in Data Structure | Skill Hives
thumnail

What Are the Different Types of Queue in Data Structure?

  • By Devraj

  • 10th November 2026

Think of a line at a railway ticket counter. The first person to arrive is served first. That is how a queue works in programming too.

A queue is a linear data structure that follows the FIFO (First In, First Out) rule. It is used in CPU scheduling, printer spooling, call centres, chat apps and many other places. Not every queue behaves the same way, though.

In this guide from Skill Hives, you will learn the main types of queue in data structure, how each works, where to use it, and how they compare.

In this article:

  • What is a queue?
  • Basic queue operations
  • Types of queue
  • Comparison table
  • Real-life applications
  • Which queue should you choose?
  • FAQs

Master Data Structures & Algorithms

Start your coding journey with Skill Hives and master technical interviews with confidence.

WhatsApp Us

What Is a Queue in Data Structure?

A queue stores elements in order. New elements are added at the rear, and elements are removed from the front.

Basic operations:

  • Enqueue: add an element at the rear
  • Dequeue: remove an element from the front
  • Peek/Front: view the front element without removing it
  • isEmpty / isFull: check the queue’s state

Types of Queue in Data Structure

There are four main types: simple, circular, priority and double-ended. Some sources also list input-restricted and output-restricted queues. These are special forms of the double-ended queue.

1. Simple Queue: Printer Jobs in an Office

Three employees send documents to the same printer. The printer handles them in the order they were received.

python

from collections import deque

print_queue = deque()

# Enqueue: jobs arrive
for job in [“Resume.pdf”, “Invoice.docx”, “Photo.png”]:
print_queue.append(job)

# Dequeue: printer processes in FIFO order
while print_queue:
print(“Printing:”, print_queue.popleft())

Output:

Printing: Resume.pdf

Printing: Invoice.docx

Printing: Photo.png

Other everyday cases: a railway or bus ticket waiting list, a bank token system, and customers waiting on a support helpline.

2. Circular Queue: Round Robin CPU Scheduling

An operating system gives each process a small slice of CPU time. If a process is unfinished, it goes to the back of the line and waits for its next turn. The line keeps cycling, like a ring. The code below uses Python’s deque to mimic that circular behaviour.

python

from collections import deque

# (process name, time needed)
processes = deque([(“P1”, 5), (“P2”, 3), (“P3″, 4)])
quantum = 2 # time slice per turn

while processes:
name, remaining = processes.popleft()
run = min(quantum, remaining)
remaining -= run
print(f”{name} runs for {run} units”)
if remaining > 0:
processes.append((name, remaining)) # back to the end of the ring
else:
print(f”{name} finished”)

Output:

P1 runs for 2 units

P2 runs for 2 units

P3 runs for 2 units

P1 runs for 2 units

P2 runs for 1 units

P2 finished

P3 runs for 2 units

P3 finished

P1 runs for 1 units

P1 finished
Other everyday cases: traffic lights cycling through red, yellow and green, and a music player on repeat.

3. Priority Queue: Hospital Emergency Room

Patients are not treated in arrival order. A heart attack patient is treated before someone with a mild fever, even if the fever patient arrived first. In this code, a lower number means higher priority.

python

import heapq

emergency_room = []

heapq.heappush(emergency_room, (3, “Fever”))
heapq.heappush(emergency_room, (1, “Heart attack”))
heapq.heappush(emergency_room, (2, “Fracture”))

while emergency_room:
priority, patient = heapq.heappop(emergency_room)
print(f”Treating: {patient} (priority {priority})”)

Output:

Treating: Heart attack (priority 1)

Treating: Fracture (priority 2)

Treating: Fever (priority 3)

Other everyday cases: Dijkstra’s shortest-path algorithm, which powers route-finding in maps, and an airline boarding order where business class boards before economy.

4. Deque (Double-Ended Queue): Browser Tabs or Undo/Redo

A deque lets you add or remove items at both ends. Imagine a list of tabs where new tabs can open at the front or the back, and either end can be closed.

python

from collections import deque

tabs = deque([“Home”, “Courses”, “Blog”])

tabs.appendleft(“Login”) # insert at front
tabs.append(“Contact”) # insert at rear
print(tabs)
# deque([‘Login’, ‘Home’, ‘Courses’, ‘Blog’, ‘Contact’])

tabs.popleft() # remove from front -> Login
tabs.pop() # remove from rear -> Contact
print(tabs)
# deque([‘Home’, ‘Courses’, ‘Blog’])
Other everyday cases: undo/redo in a text editor, and the sliding window technique in coding interviews.

5. How to Implement a Queue Using Two Stacks

You can implement a FIFO queue using two LIFO stacks: an enqueue stack (in_stack) and a dequeue stack (out_stack). When dequeuing, if out_stack is empty, all elements are popped from in_stack and pushed onto out_stack, reversing their order to achieve FIFO behavior.

python

class QueueWithTwoStacks:

def __init__(self):
self.in_stack = []
self.out_stack = []

def enqueue(self, item):
self.in_stack.append(item)

def dequeue(self):
if not self.out_stack:
while self.in_stack:
self.out_stack.append(self.in_stack.pop())
if not self.out_stack:
raise IndexError(“dequeue from empty queue”)
return self.out_stack.pop()

Queue Complexity Summary

Queue Type Enqueue Time Dequeue Time Space Complexity
Simple Queue O(1) O(1) O(n)
Circular Queue O(1) O(1) O(n)
Priority Queue (Heap) O(log n) O(log n) O(n)
Deque O(1) O(1) O(n)
Two Stacks Queue O(1) O(1) amortized O(n)

Quick Recap

Queue Type Real Example Key Behaviour
Simple Queue Printer jobs, ticket counter First come, first served
Circular Queue Round robin CPU scheduling, traffic lights Wraps around, reuses space
Priority Queue Hospital emergency room Most urgent served first
Deque Browser tabs, undo/redo Add and remove at both ends

Real-Life Applications of Queues

  • CPU scheduling: processes wait in a queue for the processor.
  • Printer spooling: print jobs are handled in arrival order.
  • Keyboard buffering: keystrokes are stored until the processor reads them.
  • Customer support systems: calls are held in order, with priority for urgent cases.
  • Graph algorithms: BFS uses a queue, and Dijkstra uses a priority queue.

Which Queue Should You Choose?

  • Need simple first-come-first-served processing? Use a simple queue.
  • Working with fixed memory and continuous data? Use a circular queue.
  • Some tasks matter more than others? Use a priority queue.
  • Need to add or remove at both ends? Use a deque.

Interview Tip from Skill Hives

Interviewers often ask:

  • Why is a circular queue better than a simple queue?
  • How do you implement a priority queue? (Answer: with a heap.)
  • What is the difference between a queue and a deque?
  • How do you implement a queue using two stacks?

Practise these with code, not just theory.

Conclusion

Queues may appear deceptively simple at first glance, yet every distinct variation serves a highly specialized purpose in computer science and software engineering. The traditional simple queue ensures fair, basic ordering through strict first-in, first-out mechanics, whereas the circular queue optimizes memory management by seamlessly recycling storage slots for continuous data streams. Meanwhile, the priority queue handles critical tasks based on urgency rather than arrival sequence, and the double-ended queue provides ultimate flexibility by permitting rapid insertions and deletions from both ends. Mastering these data structures empowers you to architect cleaner, more efficient solutions for real-world engineering challenges. Once you fully understand when and why to deploy each specific type, complex data structure and algorithm problems, along with technical interviews, will become significantly easier to conquer.

Master Data Structures & Algorithms

Ready to ace your next coding interview? Join Skill Hives for expert-led mentorship and hands-on DSA training.

WhatsApp Us

Frequently Asked Questions (FAQs)

1. What are the different types of queue in data structure?

The four main types are the simple (linear) queue, circular queue, priority queue and double-ended queue (deque). Input-restricted and output-restricted queues are special forms of the deque.

2. Which queue does not follow the FIFO principle?

The priority queue and the deque do not strictly follow FIFO. A priority queue serves elements by priority, and a deque allows insertion and deletion at both ends.

3. What is the difference between a simple queue and a circular queue?

A simple queue cannot reuse freed space at the front, which wastes memory. A circular queue connects the rear back to the front, so empty slots can be reused.

4. What is the time complexity of queue operations?

Enqueue and dequeue take O(1) in simple queues, circular queues and deques. In a heap-based priority queue, they take O(log n).

5. Where are queues used in real life?

They are used in CPU scheduling, printer spooling, keyboard buffering, call centres, message systems and graph algorithms such as BFS.

avatar
Written By
Devraj
calendar 10th November 2026
Spread the love

Your Vision, Our Expertise -
Let's Create Smart, Scalable Solutions Together