From the course: Programming Foundations: Real-World Examples

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Queues

Queues - Python Tutorial

From the course: Programming Foundations: Real-World Examples

Start my 1-month free trial

Queues

- Queues and stacks are two data structures which enable you to store and retrieve objects based on the order that they're put into the queue or stack. Queues operate on a principle called first in, first out, or FIFO. The first item to be stored in a queue will be the first item that's removed. That means when you retrieve an item from a queue, you'll always get the item that's been in queue the longest. A stack operates on a related principle called LIFO, which stands for last in, first out. That means the item which was most recently placed onto the stack will be the next one that's removed. Queues and stacks are useful in different situations. Hey, do you mind helping me put away some groceries? - Sure, no problem. - Cool, I'll make trips out to the car and bring them in the house, and if you can stay here and put them away, that'll work great. - Sounds good. - These grocery bags are objects that I'm placing into a queue. I'll place the first bag closest to Olivia. The next bag…

Contents