SlideShare a Scribd company logo
1 of 9
Stack Application
Stack Application
• Parsing in a compiler
• Undo in a word processor
• Back button in a web browser
• Postscript language for printers
• Implementing a function call in compiler
Arithmetic Expression Evaluation
• Value: push onto value stack
• Operator: push onto operator stack
• Left parenthesis: ignore
• Right parenthesis: pop operator and two values. Push the result.
( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ))
Progress Value stack Operator stack Rule
( ignore
1 Push value on value stack
+ + Push value on operator stack
( Ignore
( Ignore
2 Push value on value stack
+ + Push value on operator stack
3 Push value on value stack
) Pop top operator and last 2 value stack element.
* * Push value on operator stack
( Ignore
4 Push value on value stack
* * Push value on operator stack
5 Push value on value stack
) Pop top operator and last 2 value stack element.
) Pop top operator and last 2 value stack element.
) Pop top operator and last 2 value stack element.
Infix-postfix conversion
Algorithm
1. Scan the infix expression from left to right.
2. If the scanned character is an operand, output it.
3. Else
1. If the precedence of scanned operator is greater than the precedence of the
operator in stack or stack is empty , push it.
2. Else, pop the operator from the stack until the precedence of the second
operator is less-equal to the precedence of the operator residing on the top
of the stack. Push the scanned operator to the stack.
Algorithm- contd.
4. If the scanned operator is ‘(‘, push it to the stack.
5. If the scanned operator is ‘)’, pop and output from the stack until an
‘(‘ is encountered.
6. Repeat 2-6 until the infix expression is scanned.
7. Pop and output from stack until stack is empty.
Example Explained
A+B-C
Infix progress postfix Stack content Rule
A
+
B
-
c
A
A+
A+B
A+B-
A+B-
A+B-c
A
A
AB
AB
AB+
AB+C
AB+C-
+
+
-
-
• Write operand to output
• If stack empty, push opThis
• Write operand to output
• Stack not empty- pop item
opTop >= opThis - output opTop
Push opThis
• Write operand to output
stack not empty- pop item and output it
Thank you !!!

More Related Content

What's hot (20)

Stack
StackStack
Stack
 
Project of data structure
Project of data structureProject of data structure
Project of data structure
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Stacks
StacksStacks
Stacks
 
Application of Stack - Yadraj Meena
Application of Stack - Yadraj MeenaApplication of Stack - Yadraj Meena
Application of Stack - Yadraj Meena
 
Stack
StackStack
Stack
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stack application
Stack applicationStack application
Stack application
 
Stacks overview with its applications
Stacks overview with its applicationsStacks overview with its applications
Stacks overview with its applications
 
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 presentation
stack presentationstack presentation
stack presentation
 
Lect 15-16 Zaheer Abbas
Lect 15-16 Zaheer  AbbasLect 15-16 Zaheer  Abbas
Lect 15-16 Zaheer Abbas
 
CH4.pptx
CH4.pptxCH4.pptx
CH4.pptx
 
Stack Data Structure V1.0
Stack Data Structure V1.0Stack Data Structure V1.0
Stack Data Structure V1.0
 
Stack Data Structure
Stack Data StructureStack Data Structure
Stack Data Structure
 
Adding A Dash In jQuery:
Adding A Dash In jQuery:Adding A Dash In jQuery:
Adding A Dash In jQuery:
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Stack
StackStack
Stack
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 

Similar to Stack application

Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data StructureUshaP15
 
Binary expression tree
Binary expression treeBinary expression tree
Binary expression treeShab Bi
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxYogesh Pawar
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxprakashvs7
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURESUsha Mahalingam
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxchandankumar364348
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversionRashmiranja625
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
COMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxCOMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxasdadad5
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxPrakash Zodge
 
2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdfaniarihant
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack LavanyaJ28
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfarihantsherwani
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxKALPANAC20
 
1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree Krish_ver2
 
STACK USING LISTS.pptx
STACK USING LISTS.pptxSTACK USING LISTS.pptx
STACK USING LISTS.pptxBaby81727
 

Similar to Stack application (20)

MO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.pptMO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.ppt
 
Stack in Data Structure
Stack in Data StructureStack in Data Structure
Stack in Data Structure
 
Binary expression tree
Binary expression treeBinary expression tree
Binary expression tree
 
Unit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptxUnit 3 Stacks and Queues.pptx
Unit 3 Stacks and Queues.pptx
 
DS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptxDS-UNIT 3 FINAL.pptx
DS-UNIT 3 FINAL.pptx
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
DS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptxDS UNIT1_STACKS.pptx
DS UNIT1_STACKS.pptx
 
Stack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptxStack_Overview_Implementation_WithVode.pptx
Stack_Overview_Implementation_WithVode.pptx
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
COMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptxCOMP1603 Stacks and RPN 2023 Recording (2).pptx
COMP1603 Stacks and RPN 2023 Recording (2).pptx
 
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptxApplication of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
Application of Stack For Expression Evaluation by Prakash Zodge DSY 41.pptx
 
2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf2. Stack. Write a program that uses the stack class (you can use.pdf
2. Stack. Write a program that uses the stack class (you can use.pdf
 
Unit 2 application of stack
Unit 2  application of stack Unit 2  application of stack
Unit 2 application of stack
 
Stacks
StacksStacks
Stacks
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 
The concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdfThe concept of stack is extremely important in computer science and .pdf
The concept of stack is extremely important in computer science and .pdf
 
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptxSTACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
STACK AND ITS OPERATIONS IN DATA STRUCTURES.pptx
 
1.4 expression tree
1.4 expression tree  1.4 expression tree
1.4 expression tree
 
STACK USING LISTS.pptx
STACK USING LISTS.pptxSTACK USING LISTS.pptx
STACK USING LISTS.pptx
 

Recently uploaded

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Recently uploaded (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
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
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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 ...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

Stack application

  • 2. Stack Application • Parsing in a compiler • Undo in a word processor • Back button in a web browser • Postscript language for printers • Implementing a function call in compiler
  • 3. Arithmetic Expression Evaluation • Value: push onto value stack • Operator: push onto operator stack • Left parenthesis: ignore • Right parenthesis: pop operator and two values. Push the result. ( 1 + ( ( 2 + 3 ) * ( 4 * 5 ) ))
  • 4. Progress Value stack Operator stack Rule ( ignore 1 Push value on value stack + + Push value on operator stack ( Ignore ( Ignore 2 Push value on value stack + + Push value on operator stack 3 Push value on value stack ) Pop top operator and last 2 value stack element. * * Push value on operator stack ( Ignore 4 Push value on value stack * * Push value on operator stack 5 Push value on value stack ) Pop top operator and last 2 value stack element. ) Pop top operator and last 2 value stack element. ) Pop top operator and last 2 value stack element.
  • 6. Algorithm 1. Scan the infix expression from left to right. 2. If the scanned character is an operand, output it. 3. Else 1. If the precedence of scanned operator is greater than the precedence of the operator in stack or stack is empty , push it. 2. Else, pop the operator from the stack until the precedence of the second operator is less-equal to the precedence of the operator residing on the top of the stack. Push the scanned operator to the stack.
  • 7. Algorithm- contd. 4. If the scanned operator is ‘(‘, push it to the stack. 5. If the scanned operator is ‘)’, pop and output from the stack until an ‘(‘ is encountered. 6. Repeat 2-6 until the infix expression is scanned. 7. Pop and output from stack until stack is empty.
  • 8. Example Explained A+B-C Infix progress postfix Stack content Rule A + B - c A A+ A+B A+B- A+B- A+B-c A A AB AB AB+ AB+C AB+C- + + - - • Write operand to output • If stack empty, push opThis • Write operand to output • Stack not empty- pop item opTop >= opThis - output opTop Push opThis • Write operand to output stack not empty- pop item and output it