A stack is a linear data structure that follows the LIFO (Last In, First Out) principle.
The last element added is the first one removed — like a stack of plates.
Types of Stack Implementations:-
-
Array-based Stack:
Fixed size, fast access.
-
Linked List Stack:
Dynamic size, flexible.
-
Call Stack (System):
Used internally in function calls.
-
push(x):
Add x to top of the stack
-
pop():
Remove and return top element
-
peek():
Return the top element
-
is Empty():
Return true if stack is empty