1)What is a Stack?
A Stack is a linear data structure that follows the LIFO (Last-In-First-Out) principle. Stack
has one end, whereas the Queue has two ends (front and rear). It contains only one
pointer top pointer pointing to the topmost element of the stack. Whenever an element is
added in the stack, it is added on the top of the stack, and the element can be deleted only
from the stack. In other words, a stack can be defined as a container in which insertion
and deletion can be done from the one end known as the top of the stack.
2. Structure of stack :
Conceptually, a stack can be visualized as a collection of elements arranged in a vertical
structure, resembling a stack of plates or books.
Elements are added or removed from the top of the stack.
Unlike arrays or linked lists, stacks typically support only a limited set of operations.
2)How Does a Stack Work?
A stack follows the Last-In, First-Out (LIFO) principle, meaning the last item added to the
stack is the first one to be removed.
You can only interact with the top item of the stack.
3)Operations on a Stack :
Push: Adding an item to the top of the stack.
Pop: Removing the top item from the stack.
Peek (or Top): Looking at the top item without removing it.
Is Empty: Checking if the stack is empty.
Size: Finding out how many items are in the stack.