SlideShare a Scribd company logo
1 of 10
Stack operation algorithms
with example
KIKANI NAMAN BHARATBHAI
20SS02IT027
DATA STRUCTURES
What is Stack?
• A stack is called a last-in-first-out (LIFO) collection. This
means that the last thing we added (pushed) is the first thing
that gets pulled (popped) off.
• A stack is a sequence of items that are accessible at only one
end of the sequence.
Operations that can be performed on STACK:
 PUSH.
 POP.
Procedure/Methodology
PUSH : It is used to insert items into the stack.
POP: It is used to delete items from stack.
TOP: It represents the current location of data in stack.
ALGORITHM OF INSERTION IN STACK: (PUSH)
1. Insertion(a,top,item,max)
2. If top=max then
3. print ‘STACK OVERFLOW’
4. exit else
5. top=top+1 end if
6. a[top]=item
7. Exit
ALGORITHM OF DELETION IN STACK: (POP)
1. Deletion(a,top,item)
2. If top=0 then
3. print ‘STACK UNDERFLOW’
4. exit else
5. item=a[top] end if
6. top=top-1
7. Exit
ALGORITHM OF DISPLAY IN STACK:
• 1. Display(top,i,a[i]) 2.If top=0 then
• 2. Print ‘STACK EMPTY’
• Exit Else
• 3. For i=top to 0
• Print a[i] End for
• 4. exit
Conversion of INFIX to POSTFIX conversion:
• Example: 2+(4-1)*3 step1
• 2+41-*3 step2
• 2+41-3* step3
• 241-3*+ step4
Example:
THANK YOU

More Related Content

What's hot (20)

Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
Data structure Stack
Data structure StackData structure Stack
Data structure Stack
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue
QueueQueue
Queue
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue
QueueQueue
Queue
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
Stacks and queue
Stacks and queueStacks and queue
Stacks and queue
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
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
 
basics of queues
basics of queuesbasics of queues
basics of queues
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
U3.stack queue
U3.stack queueU3.stack queue
U3.stack queue
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Algorithm: priority queue
Algorithm: priority queueAlgorithm: priority queue
Algorithm: priority queue
 
Stack converted
Stack convertedStack converted
Stack converted
 
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)
 

Similar to Stack operation algorithms with example

Similar to Stack operation algorithms with example (20)

Ds stacks
Ds stacksDs stacks
Ds stacks
 
Stack PPT.pptx
Stack PPT.pptxStack PPT.pptx
Stack PPT.pptx
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
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
 
04 stacks
04 stacks04 stacks
04 stacks
 
Chapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdfChapter 5 Stack and Queue.pdf
Chapter 5 Stack and Queue.pdf
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Stacks Data structure.pptx
Stacks Data structure.pptxStacks Data structure.pptx
Stacks Data structure.pptx
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Stack
StackStack
Stack
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
In C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docxIn C++ a function used to put data into a stack is typically called a.docx
In C++ a function used to put data into a stack is typically called a.docx
 
stack presentation
stack presentationstack presentation
stack presentation
 
Stacks
StacksStacks
Stacks
 
Stack
StackStack
Stack
 
Introduction to stack
Introduction to stackIntroduction to stack
Introduction to stack
 
stack coding.pptx
stack coding.pptxstack coding.pptx
stack coding.pptx
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 

Stack operation algorithms with example

  • 1. Stack operation algorithms with example KIKANI NAMAN BHARATBHAI 20SS02IT027 DATA STRUCTURES
  • 2. What is Stack? • A stack is called a last-in-first-out (LIFO) collection. This means that the last thing we added (pushed) is the first thing that gets pulled (popped) off. • A stack is a sequence of items that are accessible at only one end of the sequence.
  • 3. Operations that can be performed on STACK:  PUSH.  POP.
  • 4. Procedure/Methodology PUSH : It is used to insert items into the stack. POP: It is used to delete items from stack. TOP: It represents the current location of data in stack.
  • 5. ALGORITHM OF INSERTION IN STACK: (PUSH) 1. Insertion(a,top,item,max) 2. If top=max then 3. print ‘STACK OVERFLOW’ 4. exit else 5. top=top+1 end if 6. a[top]=item 7. Exit
  • 6. ALGORITHM OF DELETION IN STACK: (POP) 1. Deletion(a,top,item) 2. If top=0 then 3. print ‘STACK UNDERFLOW’ 4. exit else 5. item=a[top] end if 6. top=top-1 7. Exit
  • 7. ALGORITHM OF DISPLAY IN STACK: • 1. Display(top,i,a[i]) 2.If top=0 then • 2. Print ‘STACK EMPTY’ • Exit Else • 3. For i=top to 0 • Print a[i] End for • 4. exit
  • 8. Conversion of INFIX to POSTFIX conversion: • Example: 2+(4-1)*3 step1 • 2+41-*3 step2 • 2+41-3* step3 • 241-3*+ step4

Editor's Notes

  1. 1