Day 12
Day 12: Introduction to Queues
12/60 Days
Introduction to Queues#
Welcome to Day 12 of our 60 Days of Coding Algorithm Challenge! Today, we’ll explore queues, another fundamental data structure that follows the First-In-First-Out (FIFO) principle.
What is a Queue?#
A queue is a linear data structure that follows a particular order in which operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.
Basic Operations of a Queue#
- Enqueue: Adds an element to the rear of the queue
- Dequeue: Removes the element from the front of the queue
- Front: Get the front element from the queue without removing it
- Rear: Get the last element from the queue without removing it
- isEmpty: Check if the queue is empty
Implementing a Queue in Python#
We can implement a queue using a Python list or create a custom class. Let’s implement both:
Using a Python List#
1class Queue:
2 def __init__(self):
3 self.items = []
4
5 def is_empty(self):
6 return len(self.items) == 0
7
8 def enqueue(self, item):
9 self.items.append(item)
10
11 def dequeue(self):
12 if not self …Keep your momentum going
Create a free account to unlock the full lesson, all 60 days, and track your progress as you go.
- Full access to all 60 daily lessons
- Track completion and build a daily streak
- Get interview-ready, one algorithm at a time
Join 2,900+ learners · 4.8/5 average rating