0
0
Data Structures Theoryknowledge~30 mins

Queue operations (enqueue, dequeue) in Data Structures Theory - Mini Project: Build & Apply

Choose your learning style9 modes available
Queue operations (enqueue, dequeue)
πŸ“– Scenario: Imagine you are managing a line of customers waiting to buy tickets at a movie theater. You need to keep track of who is in line and in what order they arrived.
🎯 Goal: You will build a simple queue system that can add customers to the line (enqueue) and remove customers from the line when they buy their tickets (dequeue).
πŸ“‹ What You'll Learn
Create a list called queue to hold customer names.
Create a variable called max_size to limit the queue length.
Add a function called enqueue to add a customer to the queue if there is space.
Add a function called dequeue to remove the first customer from the queue.
πŸ’‘ Why This Matters
🌍 Real World
Queues are used in many places like lines at stores, print job management, and customer service systems to keep things organized and fair.
πŸ’Ό Career
Understanding queue operations is important for software developers, system administrators, and anyone working with data processing or task scheduling.
Progress0 / 4 steps
1
Create the initial queue list
Create an empty list called queue to represent the line of customers waiting.
Data Structures Theory
Need a hint?

Use square brackets [] to create an empty list in Python.

2
Set the maximum queue size
Create a variable called max_size and set it to 5 to limit how many customers can wait in line.
Data Structures Theory
Need a hint?

Just assign the number 5 to the variable max_size.

3
Add the enqueue function
Write a function called enqueue that takes a parameter customer. Inside the function, add the customer to the queue list only if the length of queue is less than max_size.
Data Structures Theory
Need a hint?

Use len(queue) to check the current number of customers and queue.append(customer) to add a new one.

4
Add the dequeue function
Write a function called dequeue that removes and returns the first customer from the queue list if the queue is not empty.
Data Structures Theory
Need a hint?

Use queue.pop(0) to remove the first customer from the list.