SlideShare a Scribd company logo
Introduction to STACK
Ravi
presents ...
...
Stack
A stack is used to store elements where
the Last element In is the First one Out
(LIFO).
A common model of a stack is a plate or
coin stacker.
Plates are "pushed" onto to the top and
“pooped” off the top.
Stack
New elements are added or pushed onto
the top of the stack.
The first element to be removed or
popped is taken from the top - the last
one in.
Stack
Stack Operations
A stack is generally implemented with only two
principle operations
Push adds an item to a stack
Pop extracts the most recently pushed item from the
stack
Other methods such as
Top returns the item at the top without removing it
Isempty determines whether the stack has anything in it
Stack Implementation
Static Implementation (Using arrays)
Dynamic Implementation (Using dynamic
lists)
Stack Implementation
Using Arrays
For the static implementation of stack an
array will be used.
This array will hold the stack elements.
The top of a stack is represented by an
integer type variable which contains the
index of an array containing top element
of a stack.
Implementation of push operation on
stack
Void push(s,element)
1. If s Top=Max-1 print “Overflow stack” End If
 2. set s top=s top +1
 3. set s item[s top]=element
4. print “Element is pushed”
5. End
Stack Implementation
Using Arrays
4
3
2
1
0
Empty stack
StackSize = 5
top = -1
70
1
2
3
4
top
Push 7
70
81
2
3
4
top
Push 8 Push 9
70
81
92
3
4
top
Push 4
70
81
92
43
4
top
Push 5
70
81
92
43
54
top
top = StackSize – 1,
Stack is full,
We can’t push more elements.
Implementation of pop operation on
stack
int pop(s)
1. If s Top= -1 print “Underflow stack” return 0 and
goto step-5 End If
2. set popped=s item[s top]
3. set s top=s top -1
4. return popped
5. End
Stack Implementation Using Arrays
4
3
2
1
0
Empty stack
top = -1
We can’t pop mpre
elements
70
1
2
3
4
top
Pop
70
81
2
3
4
top
70
81
92
3
4
top
70
81
92
43
4
top
70
81
92
43
54
top
top = StackSize – 1,
Stack is full,
We can’t push more elements.
Pop
Pop
Pop Pop
THANK YOU

More Related Content

What's hot

Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
Saqib Saeed
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
Rabin BK
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
Self-Employed
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
Sunipa Bera
 
Ds stacks
Ds stacksDs stacks
Ds stacks
GIGI JOSEPH
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
Umme habiba
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
Selvin Josy Bai Somu
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
CIIT Atd.
 
Stack data structure
Stack data structureStack data structure
Stack data structure
rogineojerio020496
 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
zekeLabs Technologies
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
Victor Palmar
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Balwant Gorad
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
Devashish Kumar
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
NamanKikani
 
Stack push pop
Stack push popStack push pop
Stack push pop
A. S. M. Shafi
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
Sagacious IT Solution
 
Stack and queue
Stack and queueStack and queue
Stack and queue
CHANDAN KUMAR
 

What's hot (20)

Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Ds stacks
Ds stacksDs stacks
Ds stacks
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
stack and queue array implementation in java.
stack and queue array implementation in java.stack and queue array implementation in java.
stack and queue array implementation in java.
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Essential NumPy
Essential NumPyEssential NumPy
Essential NumPy
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 

Similar to Introduction to stack

Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
UzmaRizvi5
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Stacks
StacksStacks
stack coding.pptx
stack coding.pptxstack coding.pptx
stack coding.pptx
JamJahanzaib
 
Lecture5
Lecture5Lecture5
Lecture5
Muhammad Zubair
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
stack presentation
stack presentationstack presentation
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
Teksify
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
Praveen Vishwakarma
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
SLekshmiNair
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
Hasan Mahadi Riaz
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
Devyani Chaudhari
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
SajalFayyaz
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
rupam100
 
Stacks
StacksStacks
Stack
StackStack
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
line24arts
 
Operation on stack
Operation on stackOperation on stack
Operation on stack
chetan handa
 
Objectives- In this lab- students will practice- 1- Stack with single.pdf
Objectives- In this lab- students will practice- 1- Stack with single.pdfObjectives- In this lab- students will practice- 1- Stack with single.pdf
Objectives- In this lab- students will practice- 1- Stack with single.pdf
Augstore
 

Similar to Introduction to stack (20)

Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Stacks
StacksStacks
Stacks
 
stack coding.pptx
stack coding.pptxstack coding.pptx
stack coding.pptx
 
Lecture5
Lecture5Lecture5
Lecture5
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
stack presentation
stack presentationstack presentation
stack presentation
 
Data Structure Lecture 2
Data Structure Lecture 2Data Structure Lecture 2
Data Structure Lecture 2
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Data Structure.pptx
Data Structure.pptxData Structure.pptx
Data Structure.pptx
 
STACK.pptx
STACK.pptxSTACK.pptx
STACK.pptx
 
Stacks
StacksStacks
Stacks
 
Stack
StackStack
Stack
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Operation on stack
Operation on stackOperation on stack
Operation on stack
 
Objectives- In this lab- students will practice- 1- Stack with single.pdf
Objectives- In this lab- students will practice- 1- Stack with single.pdfObjectives- In this lab- students will practice- 1- Stack with single.pdf
Objectives- In this lab- students will practice- 1- Stack with single.pdf
 

Recently uploaded

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
IJNSA Journal
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
Victor Morales
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
thanhdowork
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
ihlasbinance2003
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
Rahul
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 

Recently uploaded (20)

bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMSA SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
A SYSTEMATIC RISK ASSESSMENT APPROACH FOR SECURING THE SMART IRRIGATION SYSTEMS
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressionsKuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
KuberTENes Birthday Bash Guadalajara - K8sGPT first impressions
 
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
RAT: Retrieval Augmented Thoughts Elicit Context-Aware Reasoning in Long-Hori...
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
5214-1693458878915-Unit 6 2023 to 2024 academic year assignment (AutoRecovere...
 
ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024ACEP Magazine edition 4th launched on 05.06.2024
ACEP Magazine edition 4th launched on 05.06.2024
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 

Introduction to stack

  • 2. Stack A stack is used to store elements where the Last element In is the First one Out (LIFO). A common model of a stack is a plate or coin stacker. Plates are "pushed" onto to the top and “pooped” off the top.
  • 3. Stack New elements are added or pushed onto the top of the stack. The first element to be removed or popped is taken from the top - the last one in.
  • 5. Stack Operations A stack is generally implemented with only two principle operations Push adds an item to a stack Pop extracts the most recently pushed item from the stack Other methods such as Top returns the item at the top without removing it Isempty determines whether the stack has anything in it
  • 6. Stack Implementation Static Implementation (Using arrays) Dynamic Implementation (Using dynamic lists)
  • 7. Stack Implementation Using Arrays For the static implementation of stack an array will be used. This array will hold the stack elements. The top of a stack is represented by an integer type variable which contains the index of an array containing top element of a stack.
  • 8. Implementation of push operation on stack Void push(s,element) 1. If s Top=Max-1 print “Overflow stack” End If  2. set s top=s top +1  3. set s item[s top]=element 4. print “Element is pushed” 5. End
  • 9. Stack Implementation Using Arrays 4 3 2 1 0 Empty stack StackSize = 5 top = -1 70 1 2 3 4 top Push 7 70 81 2 3 4 top Push 8 Push 9 70 81 92 3 4 top Push 4 70 81 92 43 4 top Push 5 70 81 92 43 54 top top = StackSize – 1, Stack is full, We can’t push more elements.
  • 10. Implementation of pop operation on stack int pop(s) 1. If s Top= -1 print “Underflow stack” return 0 and goto step-5 End If 2. set popped=s item[s top] 3. set s top=s top -1 4. return popped 5. End
  • 11. Stack Implementation Using Arrays 4 3 2 1 0 Empty stack top = -1 We can’t pop mpre elements 70 1 2 3 4 top Pop 70 81 2 3 4 top 70 81 92 3 4 top 70 81 92 43 4 top 70 81 92 43 54 top top = StackSize – 1, Stack is full, We can’t push more elements. Pop Pop Pop Pop