You are on page 1of 2

Stacks 

Thursday, September 22, 2022  8:35 PM 

Storing, organizing, accessing and DATA  Named group of homogenous


retrieving data for most efficieny data, stored in a specific way,
to provide optimal performance  STRUCTURE  that can be processed as a
single unit 
Operations      Behaviour         Properties 

Difference b/w: 
DATA TYPE  DATA STRUCTURE 
It defines the type of values we can store and The physical implementation that defines storing,
operate on.  accessing and manipulation of data stored in it. 
Values can directly be assigned to the data type Has specififc insertion and deletion 
variables 
Can hold values and not data, so it is data less  Can hold different kind and types of data within one
single object 
e.g.- int, float, etc  e.g.- stacks, queues, etc 
 

STACK 
 
Stack is a linear sequence structure or a list of elements in which insertion and deleting can take
place only at the end. 
• It is a dynamic data structure (it grows and shrinks). 
• An empty stack is known as UNDERFLOW. 
• A stack filled to it's specified capacity is known as OVERFLOW. 
 
Major Operations: 
1. Push 

It is the insertion of elements on top of a stack. 


2. Pop 
It is the deletion of elements from top of a stack. 
 
Status of a Stack: 
1. peek() 

Returns most recent value of stack. 

Gives exception if stack is empty/null. 


2. isFull() 

When we work with a fixed size stack, insertion in it results into an 'overflow' situation. 
3. isEmpty() 
When we work with an empty stack, deletion in it results into an 'underflow' situation. 
 
 
 
 
 
 
 
 
 
 
 
Implementation using a List: 
CREATING 
 
 
 
 
PUSH 
 
 
 
 
 
 
 
 
 
 
POP  
 
 
 
TRAVERSING 

 
Applications: 
1. Real-life 
a. Pile of clothes 
b. Stack of dishes 
c. Bangles on a wrist 
2. Program based 
a. Reversing a word/line 
b. To store previous state of program when fun() is called or during recursion 
c. Backtracking (form of recursion) 
d. Undo Mechanism 
 

You might also like