• Julian's Globe

    STACK

    A stack is a collection of items insterted and removed in a particular manner. It can be thought of as any other stack that comes to mind: dirty plates, homework, books, boxes, etc. The key property to understand about stacks is that the last item inserted into the stack is naturally the first one to be taken out.

    Let's go back to the dirty dishes example. When you wash dishes in the sink, you pull out the plate at the top right? You don't reach for the plate at the very bottom or in the middle, but you work your way from the top down. You wash each plate via the strategy of the last plate you placed on top being the first one you pull out to wash next. This is where the term LIFO comes in; it just stands for Last In First Out. You use the stack data structure when your problem involves data needed to be stored and retrieved in this natural manner.