SlideShare a Scribd company logo
Stacks
Stacks 
 A stack is a sequence of items that are 
accessible at only one end of the sequence. 
Stacks 2
Pushing/Popping a Stack 
 Because a pop removes the item last added to 
the stack, we say that a stack has LIFO (last-in/ 
first-out) ordering. 
Stacks 3
TOP – THE MOST RECENTLY INSERTED 
ITEM 
PUSH - TO INSERT ONTO THE TOP OF A 
STACK 
POP - TO REMOVE THE TOP ITEM IN A 
STACK 
Stacks 4
Stack Implementations 
Stacks 5 
 Array based 
 Where is top? 
 How are elements added, removed? 
 Linked List based 
 Where is top? 
 How are elements added, removed? 
 Efficiency of operations
Array Based Stack Implementation 
Where should top be? 
Stacks 6 
12 
15 
5 
2 
3 
4 
stack 
[0] array 
What are array values? 
s.push (20) 
s.pop( )
Linked List Implementation 
Stacks 7 
D 
C 
B 
t o p 
A 
S t a c k 
D C B A 
L i n k e d L i s t 
f r o n t 
s.push (‘F’) 
s.pop( )
Stack with a Singly Linked List 
 We can implement a stack with a singly linked list 
 The top element is stored at the first node of the list 
 The space used is O(n) and each operation of the Stack ADT 
takes O(1) time 
t Æ 
Stacks 8 
nodes 
elements
Thank You
Stacks 10

More Related Content

Viewers also liked

Trabajo sena
Trabajo senaTrabajo sena
Trabajo sena
TheMiangaro
 
Meg Unger Shared Learning 2014
Meg Unger Shared Learning 2014Meg Unger Shared Learning 2014
Meg Unger Shared Learning 2014
MegUnger
 
Presentation3
Presentation3Presentation3
Presentation3
Swamy Sriharsha
 
Trabajo sena 2
Trabajo sena 2Trabajo sena 2
Trabajo sena 2
TheMiangaro
 
Alcman Company - Supply Chain Solutions
Alcman Company - Supply Chain SolutionsAlcman Company - Supply Chain Solutions
Alcman Company - Supply Chain Solutions
Alcman Supply Chain Solutions
 
Trabajo3
Trabajo3Trabajo3
Trabajo3
TheMiangaro
 
Bencana terdahsyat di dunia
Bencana terdahsyat di duniaBencana terdahsyat di dunia
Bencana terdahsyat di dunia
Aulia safitri
 
7th Form, Theatre & Cinema Review
7th Form, Theatre & Cinema Review7th Form, Theatre & Cinema Review
7th Form, Theatre & Cinema Review
kristkarp
 
Världen i klassrummet
Världen i klassrummetVärlden i klassrummet
Världen i klassrummet
annawilhelmsson
 
Programmering för yngre elever
Programmering  för yngre eleverProgrammering  för yngre elever
Programmering för yngre elever
annawilhelmsson
 
Things 2
Things 2 Things 2
Things 2
annawilhelmsson
 
Att bedöma utan att döma
Att bedöma utan att döma Att bedöma utan att döma
Att bedöma utan att döma
annawilhelmsson
 

Viewers also liked (13)

Trabajo sena
Trabajo senaTrabajo sena
Trabajo sena
 
Meg Unger Shared Learning 2014
Meg Unger Shared Learning 2014Meg Unger Shared Learning 2014
Meg Unger Shared Learning 2014
 
Presentation3
Presentation3Presentation3
Presentation3
 
Trabajo sena 2
Trabajo sena 2Trabajo sena 2
Trabajo sena 2
 
AlcmanTMS 1
AlcmanTMS 1 AlcmanTMS 1
AlcmanTMS 1
 
Alcman Company - Supply Chain Solutions
Alcman Company - Supply Chain SolutionsAlcman Company - Supply Chain Solutions
Alcman Company - Supply Chain Solutions
 
Trabajo3
Trabajo3Trabajo3
Trabajo3
 
Bencana terdahsyat di dunia
Bencana terdahsyat di duniaBencana terdahsyat di dunia
Bencana terdahsyat di dunia
 
7th Form, Theatre & Cinema Review
7th Form, Theatre & Cinema Review7th Form, Theatre & Cinema Review
7th Form, Theatre & Cinema Review
 
Världen i klassrummet
Världen i klassrummetVärlden i klassrummet
Världen i klassrummet
 
Programmering för yngre elever
Programmering  för yngre eleverProgrammering  för yngre elever
Programmering för yngre elever
 
Things 2
Things 2 Things 2
Things 2
 
Att bedöma utan att döma
Att bedöma utan att döma Att bedöma utan att döma
Att bedöma utan att döma
 

Similar to Stacks

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
Ravi Khokhar
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
Information Technology Center
 
Lecture5
Lecture5Lecture5
Lecture5
Muhammad Zubair
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
Devyani Chaudhari
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
V.V.Vanniaperumal College for Women
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
Rai University
 
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
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
Rai University
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
GirT2
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
SLekshmiNair
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
vaibhav2910
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
UzmaRizvi5
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
Sunipa Bera
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
Hasan Mahadi Riaz
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
SandeepBhuma
 
Stack
StackStack
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
NamanKikani
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
Pulkitmodi1998
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
UshaP15
 

Similar to Stacks (20)

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
Lecture5
Lecture5Lecture5
Lecture5
 
DATA STRUCTURE - STACK
DATA STRUCTURE - STACKDATA STRUCTURE - STACK
DATA STRUCTURE - STACK
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
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
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Ds stack & queue
Ds   stack & queueDs   stack & queue
Ds stack & queue
 
Stack & Queue
Stack & QueueStack & Queue
Stack & Queue
 
ppt.pptx
ppt.pptxppt.pptx
ppt.pptx
 
Stack
StackStack
Stack
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 

Recently uploaded

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
[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
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
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
 
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
 
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
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
ssuser36d3051
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
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
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
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
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
rpskprasana
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
Mukeshwaran Balu
 
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
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
kandramariana6
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
SyedAbiiAzazi1
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
mamunhossenbd75
 

Recently uploaded (20)

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
[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
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
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...
 
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
 
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...
 
sieving analysis and results interpretation
sieving analysis and results interpretationsieving analysis and results interpretation
sieving analysis and results interpretation
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
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
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
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
 
CSM Cloud Service Management Presentarion
CSM Cloud Service Management PresentarionCSM Cloud Service Management Presentarion
CSM Cloud Service Management Presentarion
 
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
ACRP 4-09 Risk Assessment Method to Support Modification of Airfield Separat...
 
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
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
132/33KV substation case study Presentation
132/33KV substation case study Presentation132/33KV substation case study Presentation
132/33KV substation case study Presentation
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application14 Template Contractual Notice - EOT Application
14 Template Contractual Notice - EOT Application
 
Heat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation pptHeat Resistant Concrete Presentation ppt
Heat Resistant Concrete Presentation ppt
 

Stacks

  • 2. Stacks  A stack is a sequence of items that are accessible at only one end of the sequence. Stacks 2
  • 3. Pushing/Popping a Stack  Because a pop removes the item last added to the stack, we say that a stack has LIFO (last-in/ first-out) ordering. Stacks 3
  • 4. TOP – THE MOST RECENTLY INSERTED ITEM PUSH - TO INSERT ONTO THE TOP OF A STACK POP - TO REMOVE THE TOP ITEM IN A STACK Stacks 4
  • 5. Stack Implementations Stacks 5  Array based  Where is top?  How are elements added, removed?  Linked List based  Where is top?  How are elements added, removed?  Efficiency of operations
  • 6. Array Based Stack Implementation Where should top be? Stacks 6 12 15 5 2 3 4 stack [0] array What are array values? s.push (20) s.pop( )
  • 7. Linked List Implementation Stacks 7 D C B t o p A S t a c k D C B A L i n k e d L i s t f r o n t s.push (‘F’) s.pop( )
  • 8. Stack with a Singly Linked List  We can implement a stack with a singly linked list  The top element is stored at the first node of the list  The space used is O(n) and each operation of the Stack ADT takes O(1) time t Æ Stacks 8 nodes elements