Now that we know what a stack is, we can start talking about a queue.
And a queue is very, very similar to a stack because it's also dependent upon a specific order.
So remember, a stack was LIFO last in first out, a queue instead of being LIFO.
A queue is going to be FIFO.
And you might can guess what this is, but this is first in first.
LB So if we visualize this and we put our cue here and we push ten, we have ten.
Push 20.
We have 20.
Push 30.
We have 30.
Push 40.
We have 40.
And now if we call Pop, ten is gone.
If we call pop again, 20 is gone.
If we push, 50, 50 is there.
And if we pop one more time now, 30 is gone.
So that is first in, first out.
Basically, the oldest item in the queue is taken out.
So when would something like this be useful?
Well, I just kind of said it when we want.
The oldest item.
Item taken care of.
So think of this like a line.
You're standing in line at a store trying to pay.
Well, the longer you stand in line, you would like to hope that your position in line is getting closer
and closer to actually being able to pay for your item and check out.
And that is what a queue is.
Once you're in that line, you will eventually be the first one that was in the line.
So you will become the first one out of the line.
So when we want to get the oldest item taken care of.
And now that we know what a queue is and that we also know that it's going to be very similar to a stack.
But instead of being like, Oh, we're going to be FIFO, we're going to go implement our own queue
so that we can visualize.
How a QR code differs from a Stax.
So in the next lecture, we will begin implementing our own Q.