0
0
DSA Pythonprogramming~10 mins

Peek Front Element of Queue in DSA Python - Build from Scratch

Choose your learning style9 modes available
Peek Front Element of Queue
📖 Scenario: You are managing a line of customers waiting to buy tickets at a counter. The line is a queue where the first person to arrive is the first to be served.
🎯 Goal: Build a simple queue using a list and learn how to peek at the front customer without removing them from the line.
📋 What You'll Learn
Create a queue with exact customers in order
Add a variable to hold the front element
Access the front element without removing it
Print the front element
💡 Why This Matters
🌍 Real World
Queues are used in real life to manage lines, like customers waiting for service or tasks waiting to be processed.
💼 Career
Understanding queues and how to peek at elements is important for software development, especially in areas like task scheduling, messaging systems, and resource management.
Progress0 / 4 steps
1
Create the queue with customers
Create a list called queue with these exact customers in order: 'Alice', 'Bob', 'Charlie', 'Diana'
DSA Python
Hint

Use square brackets to create a list and separate names with commas.

2
Add a variable to hold the front element
Create a variable called front_customer and set it to the first element of the queue list using index 0
DSA Python
Hint

Use queue[0] to get the first item in the list.

3
Access the front element without removing it
Use the variable front_customer to hold the front element of the queue without removing it. (This is already done in the previous step.)
DSA Python
Hint

You already have the front element stored in front_customer.

4
Print the front element
Print the value of the variable front_customer to show the front element of the queue
DSA Python
Hint

Use print(front_customer) to display the front customer.