0
0
Data Structures Theoryknowledge~30 mins

Circular queue in Data Structures Theory - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Circular Queue
πŸ“– Scenario: Imagine you are managing a small parking lot with a fixed number of parking spaces arranged in a circle. Cars enter and leave the lot in order, and when the lot is full, new cars must wait until a space is free. This setup works like a circular queue.
🎯 Goal: Build a simple circular queue model using a list and pointers to track the front and rear positions. You will create the data structure, set up control variables, implement the logic to add and remove cars, and finalize the queue management.
πŸ“‹ What You'll Learn
Create a list called parking_lot with 5 empty slots represented by None
Create two variables called front and rear both set to -1
Write a function called enqueue(car) that adds a car to the circular queue if space is available
Write a function called dequeue() that removes a car from the circular queue if it is not empty
πŸ’‘ Why This Matters
🌍 Real World
Circular queues are used in real-world systems like traffic lights, CPU scheduling, and buffering data streams where resources are reused in a cycle.
πŸ’Ό Career
Understanding circular queues helps in software development roles involving system design, embedded systems, and performance optimization.
Progress0 / 4 steps
1
Create the parking lot list
Create a list called parking_lot with exactly 5 slots, each initialized to None to represent empty parking spaces.
Data Structures Theory
Need a hint?

Use square brackets to create a list with 5 None elements.

2
Set up front and rear pointers
Create two variables called front and rear and set both to -1 to indicate the queue is initially empty.
Data Structures Theory
Need a hint?

Set both front and rear to -1 to show the queue is empty.

3
Write the enqueue function
Write a function called enqueue(car) that adds a car to the parking_lot circular queue. It should update rear and handle wrapping around. If the queue is full, do nothing.
Data Structures Theory
Need a hint?

Use modulo % to wrap rear around the list length.

4
Write the dequeue function
Write a function called dequeue() that removes a car from the parking_lot circular queue. It should update front and handle wrapping around. If the queue is empty, do nothing.
Data Structures Theory
Need a hint?

Reset front and rear to -1 when queue becomes empty.