A stack is a linear data structure in which objects are stacked on top of each other and can only be accessed from the top. Elements are placed in LIFO (Last-In-First-Out) or FILO (First-In, Last-Out) order.
LIFO is the acronym for 'last in, first out' and refers to the stack data structure. In a LIFO data structure, the most recently added member to the stack is processed first. In contrast, FIFO stands for 'first in, first out' & uses a queue data structure.
There are two main methods for implementing a stack:
Array-based stacks have a limited size, thus you can only add or remove elements up to the array's size.
Linked list-based stacks have no defined size, so you can add and remove as many elements as you wish.
There are 2 types of Stack:
Fixed-size stacks have a fixed capacity and cannot be changed. When attempting to add an element to a full stack, an overflow error occurs, whereas removing an element from an empty stack causes an underflow error.
The Dynamic Size Stack can change its size as needed. Expands when full to accommodate new parts; contracts when empty. Implemented linked lists for simple scaling.