SlideShare a Scribd company logo
1 of 12
Stack
By- Ashish Ranjan
What is Stack ?
○ A stack is an Abstract Data Type (ADT), commonly used in
most programming languages.
○ It is named stack as it behaves like a real-world stack, for
example – a deck of cards or a pile of plates, etc.
○ A real-world stack allows operations at one end only. For
example, we can place or remove a card or plate from the
top of the stack only.
○ This feature makes it LIFO data structure. LIFO stands for
Last-in-first-out. Here, the element which is placed
(inserted or added) last, is accessed first. In stack
terminology, insertion operation is called PUSH operation
and removal operation is called POP operation.
2
Stack Representation
The following diagram depicts a stack and its operations −
3
Basic
Operations
○ push() − Pushing (storing) an element
on the stack.
○ pop() − Removing (accessing) an
element from the stack.
○ peek() − get the top data element of the
stack, without removing it.
○ isFull() − check if stack is full.
○ isEmpty() − check if stack is empty.
4
1.
Push Operation
The process of putting a
new data element onto
stack is known as a Push
Operation.
“Push operation involves a series of steps −
○ Step 1 − Checks if the stack is full.
○ Step 2 − If the stack is full, produces an error and exit.
○ Step 3 − If the stack is not full, increments top to point next
empty space.
○ Step 4 − Adds data element to the stack location, where
top is pointing.
○ Step 5 − Returns success.
6
7
2.
Pop Operation
Accessing the content while
removing it from the stack,
is known as a Pop
Operation.
“Pop operation involves a series of steps −
○ Step 1 − Checks if the stack is empty.
○ Step 2 − If the stack is empty, produces an error and exit.
○ Step 3 − If the stack is not empty, accesses the data
element at which top is pointing.
○ Step 4 − Decreases the value of top by 1.
○ Step 5 − Returns success.
9
10
When data is
PUSHED in
the stack.
peek() − get
the top data
element of
the stack,
without
removing it.
isEmpty() −
check if
stack is
empty.
isFull() −
check if
stack is full.
11
To use a stack efficiently, we need to check the
status of stack as well. For the same purpose,
the following functionality is added to stacks −
Thank You
12

More Related Content

What's hot

STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureYaksh Jethva
 
Project of data structure
Project of data structureProject of data structure
Project of data structureUmme habiba
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturergomathi chlm
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with exampleNamanKikani
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operationSenthil Kumar
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data StructureRabin BK
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queuesAbbott
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesSnehilKeshari
 
Stack organization
Stack organizationStack organization
Stack organizationchauhankapil
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 

What's hot (20)

STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Stack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi LecturerStack and Queue by M.Gomathi Lecturer
Stack and Queue by M.Gomathi Lecturer
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Data structure stack&queue basics
Data structure stack&queue   basicsData structure stack&queue   basics
Data structure stack&queue basics
 
Stack
StackStack
Stack
 
My lecture stack_queue_operation
My lecture stack_queue_operationMy lecture stack_queue_operation
My lecture stack_queue_operation
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queuesFallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
Fallsem2015 16 cp1699-20-jul-2015_rm01_stacks_and_queues
 
Stack converted
Stack convertedStack converted
Stack converted
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Introduction To Stack
Introduction To StackIntroduction To Stack
Introduction To Stack
 
Stack organization
Stack organizationStack organization
Stack organization
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Queue
QueueQueue
Queue
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Stack
StackStack
Stack
 

Similar to Stack

Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdfTobyWtf
 
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 QueueBalwant Gorad
 
Chapter 5-stack.pptx
Chapter 5-stack.pptxChapter 5-stack.pptx
Chapter 5-stack.pptxHalid Assen
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queuePulkitmodi1998
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data StructureUshaP15
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfGirT2
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptxline24arts
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptxskilljiolms
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxShivam Kumar
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationRAtna29
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queueRajkiran Nadar
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxSLekshmiNair
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEswathirajstar
 

Similar to Stack (20)

Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Stacks-and-Queues.pdf
Stacks-and-Queues.pdfStacks-and-Queues.pdf
Stacks-and-Queues.pdf
 
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
 
Chapter 5-stack.pptx
Chapter 5-stack.pptxChapter 5-stack.pptx
Chapter 5-stack.pptx
 
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
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Chapter 4 stack
Chapter 4 stackChapter 4 stack
Chapter 4 stack
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
04 stacks
04 stacks04 stacks
04 stacks
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Stack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptxStack and its operation implemented with array new - Copy.pptx
Stack and its operation implemented with array new - Copy.pptx
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
Lecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptxLecture#5 - Stack ADT.pptx
Lecture#5 - Stack ADT.pptx
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
DSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUEDSA- Unit III- STACK AND QUEUE
DSA- Unit III- STACK AND QUEUE
 
DS UNIT 1.pdf
DS UNIT 1.pdfDS UNIT 1.pdf
DS UNIT 1.pdf
 

Recently uploaded

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

Stack

  • 2. What is Stack ? ○ A stack is an Abstract Data Type (ADT), commonly used in most programming languages. ○ It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc. ○ A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only. ○ This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation. 2
  • 3. Stack Representation The following diagram depicts a stack and its operations − 3
  • 4. Basic Operations ○ push() − Pushing (storing) an element on the stack. ○ pop() − Removing (accessing) an element from the stack. ○ peek() − get the top data element of the stack, without removing it. ○ isFull() − check if stack is full. ○ isEmpty() − check if stack is empty. 4
  • 5. 1. Push Operation The process of putting a new data element onto stack is known as a Push Operation.
  • 6. “Push operation involves a series of steps − ○ Step 1 − Checks if the stack is full. ○ Step 2 − If the stack is full, produces an error and exit. ○ Step 3 − If the stack is not full, increments top to point next empty space. ○ Step 4 − Adds data element to the stack location, where top is pointing. ○ Step 5 − Returns success. 6
  • 7. 7
  • 8. 2. Pop Operation Accessing the content while removing it from the stack, is known as a Pop Operation.
  • 9. “Pop operation involves a series of steps − ○ Step 1 − Checks if the stack is empty. ○ Step 2 − If the stack is empty, produces an error and exit. ○ Step 3 − If the stack is not empty, accesses the data element at which top is pointing. ○ Step 4 − Decreases the value of top by 1. ○ Step 5 − Returns success. 9
  • 10. 10
  • 11. When data is PUSHED in the stack. peek() − get the top data element of the stack, without removing it. isEmpty() − check if stack is empty. isFull() − check if stack is full. 11 To use a stack efficiently, we need to check the status of stack as well. For the same purpose, the following functionality is added to stacks −