2. 5. Stack Operations
CONTENTS
3. Array Representation of Stack
6. Applications of Stack
2. Representation of Stack
4. Linked List Representation of Stack
1. Overview of Stack
5. Operation
Definition
All operations will be performed at only one end
of the stack that is from the top.
It works in LIFO manner: Last In First Out or FILO
manner: First In Last Out.
A stack is a linear data structure.
Examples
Examples: stack of plates, books, etc.
Working Principle
What is a Stack?
9. In this method, an array is used to represent the
stack.
Array Representation of Stack
Variables used in this method:
• TOP - storing the index where the last is held
in an array representing the stack.
• MAX - define how many maximum elements
can be stored in an array representing the stack.
13. 5
Top Element
pop(): Remove and
return the top
element.
Stack Operations
isFull(): Checks if
the stack is full.
push(x): Add
element x to the
top.
1
Remove
Element isEmpty(): Checks
if the stack is
empty.
4
2
Add Element Check Full
peek()/top():
Return top
element without
removing it.
Check Empty
3
15. Reversing Data
Applications of Stack
Call Stack
History Tracking
Browser Tracking
Function Management Expression Evaluation
e.g., 8-Queens problem
Operations
Backtracking
Infix, Prefix, Postfix Expression
Data Reversal
Undo/Redo