SlideShare a Scribd company logo
Lecture Note-6: Stack Operations 2015
By Rajesh K Shukla, HOD, Department of CSE, SIRT Bhopal
Downloaded from www.RajeshkShukla.com
Stack Operations
There are two basic operations that are usually performed with stacks.
1. PUSH
2. POP
Let us discuss POP Operation in detail.
POP Operation
POP Operation is basically used to remove the elements from the stack. This is the process used to delete
the elements from the stack. So when we say pop an element we mean delete an element from the stack.
Suppose we want to remove all the five elements from the stack shown in figure 3.6, the graphical
representation of such removal from the Stack is shown here in figure 3.7
The most recently inserted element i.e. E is at the Top so it is deleted first from the stack. The second to top
element i.e. D is deleted next because the previous top element E is removed so the next older item D in the
stack becomes the new Top element. The value of Top is changed after the deletion in Stack takes place. In
this way the element inserted first i.e. A is deleted last from the stack. When the last item in the stack is
deleted the stack is set to empty state. The elements from the stack are always retrieved in the reverser order
as we can see from figure 3.7 the elements are removed in the reverse order (E, D, C, B, A) in which they
were pushed (A, B, C, D, E) into the stack as shown in figure 3.6. Removal of an element depends upon its
position in the stack; you have to first remove all the elements above it. Therefore you cannot delete B unless
all the elements above it i.e. C, D and E are removed. We can see in the figure 3.7 that after every pop
operation the stack Top is decremented by one. The most frequently accessible element in the stack is the
topmost element whereas the least accessible element is the bottom of the stack. When all the elements from
the stack are removed mean stack is empty then we cannot delete anything from the stack. This situation is
called Underflow. If the pop operation is performed in the empty stack then the stack underflow condition
occurs so one must test whether there is an element in the stack to be deleted. We can perform the pop
operation only when the stack is not empty. The algorithm for POP operation is given below as
ALGORITHM-2. Let STACK is an array of MAX size and we want to delete the ELEMENT from the
STACK
ALGORITHM-2: POP (STACK, MAX, TOP, ITEM)
Step1. Check for Underflow
If Top=-1 then Print “Underflow” and Return
Else
a. ELEMENT =STACK[Top] // Delete an ELEMENT from the STACK
b. Top=Top-1 // Decrement the Top by One
End if
Step2. Return
Fig 3.7: Graphical representation of Stack POP Operation
4
3
2
1
0
E
D
C
B
A
T
o
4
3
2
1
0
3
2
1
0
D
C
B
A
T
o
2
1
0
C
B
A
T
o
4
3
2
1
0
E
D
C
B
A
T
o
4
3
2
1
0
E
D
C
B
A
T
o
Top=4(stack is given) Top=3(E is Removed) Top=2(D is Removed) Top=1(C is Removed) Top=0(B is Removed) Top=-1(A is Removed)

More Related Content

What's hot

DBMS PPT
DBMS PPTDBMS PPT
DBMS PPT
Prabhu Goyal
 
Joins
Joins Joins
Joins
Bihara singh
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
Janki Shah
 
Open addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashingOpen addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashing
SangeethaSasi1
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
bca2010
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMSkoolkampus
 
Intro to trigger and constraint
Intro to trigger and constraintIntro to trigger and constraint
Intro to trigger and constraintLearningTech
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applicationsSaqib Saeed
 
Using binary classifiers
Using binary classifiersUsing binary classifiers
Using binary classifiersbutest
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data StructureAnuj Modi
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
Jeanie Arnoco
 
Max flow min cut
Max flow min cutMax flow min cut
Max flow min cut
Mayank Garg
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 

What's hot (20)

DBMS PPT
DBMS PPTDBMS PPT
DBMS PPT
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
Joins
Joins Joins
Joins
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Open addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashingOpen addressiing &rehashing,extendiblevhashing
Open addressiing &rehashing,extendiblevhashing
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS12. Indexing and Hashing in DBMS
12. Indexing and Hashing in DBMS
 
Intro to trigger and constraint
Intro to trigger and constraintIntro to trigger and constraint
Intro to trigger and constraint
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
Using binary classifiers
Using binary classifiersUsing binary classifiers
Using binary classifiers
 
B trees in Data Structure
B trees in Data StructureB trees in Data Structure
B trees in Data Structure
 
Quick sort-Data Structure
Quick sort-Data StructureQuick sort-Data Structure
Quick sort-Data Structure
 
Max flow min cut
Max flow min cutMax flow min cut
Max flow min cut
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Selection sort
Selection sortSelection sort
Selection sort
 
Cs419 lec10 left recursion and left factoring
Cs419 lec10   left recursion and left factoringCs419 lec10   left recursion and left factoring
Cs419 lec10 left recursion and left factoring
 
First() and Follow()
First() and Follow()First() and Follow()
First() and Follow()
 

Viewers also liked

Super ontology stack_review_m36_051
Super ontology stack_review_m36_051Super ontology stack_review_m36_051
Super ontology stack_review_m36_051
John Domingue
 
Stack: Recursion and Iteration
Stack: Recursion and IterationStack: Recursion and Iteration
Stack: Recursion and Iteration
Rajesh K Shukla
 
Quiz 2
Quiz 2Quiz 2
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
Zidny Nafan
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Safin Biswas
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 
Stack data structure
Stack data structureStack data structure
Stack data structureTech_MX
 
Stack Applications
Stack ApplicationsStack Applications
Applications of stack
Applications of stackApplications of stack
Applications of stack
eShikshak
 
Stack
StackStack
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
Archie Jamwal
 
Data structure and algorithm with java implementation by obaid kakar
Data structure and algorithm with java implementation by obaid kakarData structure and algorithm with java implementation by obaid kakar
Data structure and algorithm with java implementation by obaid kakar
Obaid Kakar
 

Viewers also liked (13)

Super ontology stack_review_m36_051
Super ontology stack_review_m36_051Super ontology stack_review_m36_051
Super ontology stack_review_m36_051
 
Stack: Recursion and Iteration
Stack: Recursion and IterationStack: Recursion and Iteration
Stack: Recursion and Iteration
 
Graphical representation of Stack
Graphical representation of StackGraphical representation of Stack
Graphical representation of Stack
 
Quiz 2
Quiz 2Quiz 2
Quiz 2
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)Stack in microprocessor 8085(presantation)
Stack in microprocessor 8085(presantation)
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stack
StackStack
Stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Data structure and algorithm with java implementation by obaid kakar
Data structure and algorithm with java implementation by obaid kakarData structure and algorithm with java implementation by obaid kakar
Data structure and algorithm with java implementation by obaid kakar
 

Similar to Pop operation

Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
kalyanineve
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
Yaksh Jethva
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stackvaibhav2910
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
SonaPathak4
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
DurgaDeviCbit
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
UzmaRizvi5
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Soumyajit Pal
 
Stack operations using array
Stack operations using arrayStack operations using array
Stack operations using array
aluavi
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
V.V.Vanniaperumal College for Women
 
Stack push pop
Stack push popStack push pop
Stack push pop
A. S. M. Shafi
 
Stack operation
Stack operationStack operation
Stack operation
AnujRana43
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
Praveen Vishwakarma
 
Operation on stack
Operation on stackOperation on stack
Operation on stack
chetan handa
 
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
RAtna29
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
poongothai11
 
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
StackStack

Similar to Pop operation (20)

Unit 3 stack
Unit 3   stackUnit 3   stack
Unit 3 stack
 
STACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data StructureSTACK ( LIFO STRUCTURE) - Data Structure
STACK ( LIFO STRUCTURE) - Data Structure
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Module 2 ppt.pptx
Module 2 ppt.pptxModule 2 ppt.pptx
Module 2 ppt.pptx
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack operations using array
Stack operations using arrayStack operations using array
Stack operations using array
 
Stack and its operations
Stack and its operationsStack and its operations
Stack and its operations
 
Stack push pop
Stack push popStack push pop
Stack push pop
 
Stack operation
Stack operationStack operation
Stack operation
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Operation on stack
Operation on stackOperation on stack
Operation on stack
 
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
 
Stack and its operations, Queue and its operations
Stack and its operations, Queue and its operationsStack and its operations, Queue and its operations
Stack and its operations, Queue and its operations
 
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
StackStack
Stack
 

More from Rajesh K Shukla

Quiz 1
Quiz 1Quiz 1
Little o and little omega
Little o and little omegaLittle o and little omega
Little o and little omega
Rajesh K Shukla
 
Theta notation
Theta notationTheta notation
Theta notation
Rajesh K Shukla
 
The bog oh notation
The bog oh notationThe bog oh notation
The bog oh notation
Rajesh K Shukla
 
Big omega
Big omegaBig omega
Big omega
Rajesh K Shukla
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
Rajesh K Shukla
 
Lecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of AlgorithmsLecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of Algorithms
Rajesh K Shukla
 

More from Rajesh K Shukla (7)

Quiz 1
Quiz 1Quiz 1
Quiz 1
 
Little o and little omega
Little o and little omegaLittle o and little omega
Little o and little omega
 
Theta notation
Theta notationTheta notation
Theta notation
 
The bog oh notation
The bog oh notationThe bog oh notation
The bog oh notation
 
Big omega
Big omegaBig omega
Big omega
 
Lecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its PropertiesLecture Note-1: Algorithm and Its Properties
Lecture Note-1: Algorithm and Its Properties
 
Lecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of AlgorithmsLecture Note-2: Performance analysis of Algorithms
Lecture Note-2: Performance analysis of Algorithms
 

Recently uploaded

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

Pop operation

  • 1. Lecture Note-6: Stack Operations 2015 By Rajesh K Shukla, HOD, Department of CSE, SIRT Bhopal Downloaded from www.RajeshkShukla.com Stack Operations There are two basic operations that are usually performed with stacks. 1. PUSH 2. POP Let us discuss POP Operation in detail. POP Operation POP Operation is basically used to remove the elements from the stack. This is the process used to delete the elements from the stack. So when we say pop an element we mean delete an element from the stack. Suppose we want to remove all the five elements from the stack shown in figure 3.6, the graphical representation of such removal from the Stack is shown here in figure 3.7 The most recently inserted element i.e. E is at the Top so it is deleted first from the stack. The second to top element i.e. D is deleted next because the previous top element E is removed so the next older item D in the stack becomes the new Top element. The value of Top is changed after the deletion in Stack takes place. In this way the element inserted first i.e. A is deleted last from the stack. When the last item in the stack is deleted the stack is set to empty state. The elements from the stack are always retrieved in the reverser order as we can see from figure 3.7 the elements are removed in the reverse order (E, D, C, B, A) in which they were pushed (A, B, C, D, E) into the stack as shown in figure 3.6. Removal of an element depends upon its position in the stack; you have to first remove all the elements above it. Therefore you cannot delete B unless all the elements above it i.e. C, D and E are removed. We can see in the figure 3.7 that after every pop operation the stack Top is decremented by one. The most frequently accessible element in the stack is the topmost element whereas the least accessible element is the bottom of the stack. When all the elements from the stack are removed mean stack is empty then we cannot delete anything from the stack. This situation is called Underflow. If the pop operation is performed in the empty stack then the stack underflow condition occurs so one must test whether there is an element in the stack to be deleted. We can perform the pop operation only when the stack is not empty. The algorithm for POP operation is given below as ALGORITHM-2. Let STACK is an array of MAX size and we want to delete the ELEMENT from the STACK ALGORITHM-2: POP (STACK, MAX, TOP, ITEM) Step1. Check for Underflow If Top=-1 then Print “Underflow” and Return Else a. ELEMENT =STACK[Top] // Delete an ELEMENT from the STACK b. Top=Top-1 // Decrement the Top by One End if Step2. Return Fig 3.7: Graphical representation of Stack POP Operation 4 3 2 1 0 E D C B A T o 4 3 2 1 0 3 2 1 0 D C B A T o 2 1 0 C B A T o 4 3 2 1 0 E D C B A T o 4 3 2 1 0 E D C B A T o Top=4(stack is given) Top=3(E is Removed) Top=2(D is Removed) Top=1(C is Removed) Top=0(B is Removed) Top=-1(A is Removed)