0% found this document useful (0 votes)
40 views

Chapter-6 Data Structures (Notes)

Stacks are a linear data structure that follows the LIFO (Last In First Out) principle for inserting and removing items. Elements can only be inserted and removed from one end, called the top of the stack. The three main operations on a stack are push to insert an element, pop to remove an element, and peek to view the top element without removing it. Stacks have common real-world applications like piles of objects and undo mechanisms in programs, as well as algorithmic uses like recursion and backtracking.

Uploaded by

Himanshi Tomer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Chapter-6 Data Structures (Notes)

Stacks are a linear data structure that follows the LIFO (Last In First Out) principle for inserting and removing items. Elements can only be inserted and removed from one end, called the top of the stack. The three main operations on a stack are push to insert an element, pop to remove an element, and peek to view the top element without removing it. Stacks have common real-world applications like piles of objects and undo mechanisms in programs, as well as algorithmic uses like recursion and backtracking.

Uploaded by

Himanshi Tomer
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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