Introduction to Stack-1
Introduction to Stack-1
A stack is a linear data structure that follows the LIFO (Last In, First Out) principle.
This means the last element added to the stack will be the first one to be removed.
Characteristics of a Stack
Visualization of a Stack
Initial Stack: []
Push 5: [5]
Push 10: [5, 10]
Push 20: [5, 10, 20]
Pop: [5, 10] (20 removed)
Peek: 10 (top element)
The PUSH operation is used to add an element to the top of the stack.
The POP operation is used to remove the top element from the stack and return it.
Problem Statement:
Example Execution
Stack: []
In summary,