24 - Stacks
In this tutorial, we will look at using stacks in Unity.
A stack is a collection which is Last In First Out (LIFO). What does it mean to be LIFO? LIFO means that as objects are added to the stack they are 'pushed' on top of the previous objects in the stack. When objects are 'popped' out of the stack, they are done so where the last object is the first one that you receive. So what are stacks useful for? There are a few tree algorithms that utilize stacks to recognize how they are traversing the tree. Some other examples are putting items in a box. You generally take out items from the box in the opposite order that you put them in.
The first operation that we will talk about with stacks is how to add objects to a stack, also known as pushing.
The next step that we will look at is how to pop objects out of the stack.
In this tutorials we went over what stacks are and how to use them. There are many different methods that you can use within the stack class. I recommend you explore all the options so that you can make the most out of stacks.