Data Structure (Stack) Notes by Nitin Paliwal
Data Structure (Stack) Notes by Nitin Paliwal
NITIN PALIWAL
Page 2
DATA STRUCTURE
A data structure defines a mechanism to store, organise and access data along with
operations (processing) that can be efficiently performed on the data.
STACK
Introduction to Stack
Analogous to piles of books or plates at home.
New items are added to and removed from the top of the pile.
Conventional to add/remove objects only from the top due to
convenience.
This linear order of arrangement is termed as a stack.
APPLICATIONS OF STACK
Real-Life Applications
Piles of clothes in an almirah.
Vertical stacks of chairs.
Bangles worn on the wrist.
Piles of boxes of eatables in a pantry or kitchen shelf.
Programming Applications
String Reversal: Easily achieved by placing characters of a
string in a stack and retrieving them in reverse order.
Text/Image Editing: Stack keeps track of changes made,
enabling redo/undo functionalities in text/image editors.
Web Browsing: Back button functionality in browsers is
implemented using a stack to maintain the history of visited web
pages.
Arithmetic Expressions: Used to handle matching of
parentheses in arithmetic expressions, ensuring proper nesting
and throwing errors for mismatched parentheses.
NITIN PALIWAL
Page 3
OPERATIONS ON STACK
Stack Fundamentals
Stack implements Last-In-First-Out (LIFO) arrangement.
Elements are added to and deleted from one end, termed as the TOP
of the stack.
Key Operations
PUSH: Adds a new element at the top of the stack.
Insertion operation.
Continues until the stack is full, resulting in an 'overflow'
exception if attempted beyond capacity.
POP: Removes the topmost element of the stack.
Deletion operation.
Continues until the stack is empty, resulting in an 'underflow'
exception if attempted on an empty stack.
IMPLEMENTATION OF STACK
NITIN PALIWAL
Page 4
NITIN PALIWAL
Page 5
NITIN PALIWAL