From the course: Programming Foundations: Data Structures (2023)
Unlock the full course today
Join today to access over 24,400 courses taught by industry experts.
What is a queue? - Python Tutorial
From the course: Programming Foundations: Data Structures (2023)
What is a queue?
- Queues represent a series of ordered objects but the way we access, add and remove items is slightly different from lists. If you think of a queue at an amusement park or a line of people at a store, a queue has a front and back and it works the same way in code. It's designed to have elements inserted at the end of the queue and elements removed from the beginning of the queue. When people stand in a line, the first person that gets in the line is the first person out of the line, and the last person in the line is the last person out of the line. We say queues follow a FIFO or a first-in, first-out policy for this reason. Some important terminology to keep in mind is enqueue and dequeue. When we add an item to a queue, we say we enqueue the item and when we remove an item from the queue we say we dequeue the item. We can also peek or see the first item in the queue without removing it from the data structure.…