Introduction
The stack data structure follows the LIFO (Last In First Out) principle. That is, the element added last will be removed first. Stack uses an encapsulated object of either vector or deque (by default) or list as its underlying container, providing a specific set of member functions to access its elements.
Advantages
- Fast insertion, deletion and access operations.
- Can be used to solve problems that work with recursion.
Disadvantages
- Limited number of methods.
- Random access of elements is impossible in stacks.
- Stacks are neither flexible nor scalable.