In this lecture, we are now going to talk about what a stack is.
And a stack is something that we have been talking about.
If you remember when we would say we would unwind the stack when referring to recursion.
So we were now going to get a better insight as to what a stack actually is.
So the first thing to know about a stack is there's a specific order in which we can insert and remove
elements so specific.
Order in how.
We insert.
And remove.
Elements.
And now this order actually has its own acronym, and it is called LIFO.
And LIFO is last in.
First out.
Meaning we can insert at.
The top.
And then take from the top.
So think of this as a stack of plates.
And I like to think of it as a stack of plates, because when you put plates into the cabinet, if you
add a plate here, well, you're not going to take this plate.
You're going to take the plate that you recently just add it in.
So then you would take that plate.
So last in, first out.
So when we look at a stack, we'll say that this is our stack.
We will say push ten.
Well, now we have ten here.
And then if we push 20 and now we have 20 here, push 30.
Now we have 30 here.
But then if we call Pop.
Now 30 is gone.
And then if we push 40, now 40 is here.
And if we call pop again now 40 is gone.
So this might seem very similar to something that we just did.
So let's just so our stack is here.
Our top is here.
We insert at the top,
we remove.
From the top, so this might seem very familiar.
We just did something like this with our linked list Every time we put in a new value when we called
pop, that latest value that we pushed in was removed.
And that is because you might have guessed it, we implemented a stacked base.
Linked list.
So while we were learning Linked List, we were actually implementing a stack as well.
So that is why we're not going to spend too much time talking about a stack, because while we were
learning linked lists, we also learned what a stack is and how to implement a stack.
But.
A stack does have a counterpart and and its counterpart is a Q.
So in the next lecture we will go over what a Q is and then we will implement our own Q.