April 2018
Intermediate to advanced
300 pages
7h 41m
English
Stacks maintain a collection of items in Last In First Out (LIFO) order. The last item to be inserted is retrieved first. Only two operations are allowed on stacks, namely push and pop. The real application of a stack is an undo operation that inserts the changes into the stack and, on undoing, removes the last action that was performed:

The preceding diagram illustrates how the items are added to the stack. The last inserted item pops out first, and to access the first item that was inserted, we have to pop out each element until it reaches the first one.
Here are a few of the circumstance where stacks are useful: