SlideShare a Scribd company logo
What is Stack ?
A stack is a list of elements in which an element may be inserted or deleted only at one end,
called the top of the stack. Stacks are sometimes known as LIFO (last in, first out). This means
that last thing we added (pushed) is the first thing that gets pulled (popped) off .
A stack is sequence of items that are accessible at only one end of the sequence.
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Ds stack 03
Infix to Postfix
Infix Postfix
A + B A B +
12 + 60 – 23 12 60 + 23 –
(A + B)*(C – D ) A B + C D – *
A ↑ B * C – D + E/F A B ↑ C*D – E F/+
Infix to Postfix
Note that the postfix form an expression does not require parenthesis.
Consider ‘4+3*5’ and ‘(4+3)*5’. The parenthesis are not needed in the first
but they are necessary in the second.
The postfix forms are:
4+3*5 435*+
(4+3)*5 43+5*
Evaluating Postfix
Each operator in a postfix expression refers to the previous two operands.
Each time we read an operand, we push it on a stack.
When we reach an operator, we pop the two operands from the top of the stack,
apply the operator and push the result back on the stack.
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
↑ 7 2 49 49
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
↑ 7 2 49 49
3 7 2 49 49,3
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
↑ 7 2 49 49
3 7 2 49 49,3
+ 49 3 52 52
Evaluating Postfix
Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 +
Input op1 op2 value stack
6 6
2 6,2
3 6,2,3
+ 2 3 5 6,5
- 6 5 1 1
3 6 5 1 1,3
8 6 5 1 1,3,8
2 6 5 1 1,3,8,2
/ 8 2 4 1,3,4
+ 3 4 7 1,7
* 1 7 7 7
2 1 7 7 7,2
↑ 7 2 49 49
3 7 2 49 49,3
+ 49 3 52 52
Ds stack 03

More Related Content

PPT
Computer notes - Postfix
PPT
computer notes - Data Structures - 7
PPT
PPTX
5.stack
PPT
Stack application
PPTX
Stack data structure
PPTX
Application of Stack - Yadraj Meena
PDF
Transition graph using free monads and existentials
Computer notes - Postfix
computer notes - Data Structures - 7
5.stack
Stack application
Stack data structure
Application of Stack - Yadraj Meena
Transition graph using free monads and existentials

What's hot (19)

PPSX
Stacks Implementation and Examples
PDF
Applications of stack
PPT
PPTX
Nested loops
PPT
Stacks
PPTX
Stack and its Applications : Data Structures ADT
PPTX
Working of while loop
PPSX
PDF
The Ring programming language version 1.3 book - Part 6 of 88
PDF
The Ring programming language version 1.10 book - Part 14 of 212
PDF
stack
PPT
Stack Operation In Data Structure
PDF
The Ring programming language version 1.5.2 book - Part 25 of 181
PDF
81818088 isc-class-xii-computer-science-project-java-programs
PPTX
Scope and closures
PPT
Conversion of Infix To Postfix Expressions
PPSX
Stacks fundamentals
PPTX
stack
PPTX
Refactoring
Stacks Implementation and Examples
Applications of stack
Nested loops
Stacks
Stack and its Applications : Data Structures ADT
Working of while loop
The Ring programming language version 1.3 book - Part 6 of 88
The Ring programming language version 1.10 book - Part 14 of 212
stack
Stack Operation In Data Structure
The Ring programming language version 1.5.2 book - Part 25 of 181
81818088 isc-class-xii-computer-science-project-java-programs
Scope and closures
Conversion of Infix To Postfix Expressions
Stacks fundamentals
stack
Refactoring
Ad

Similar to Ds stack 03 (20)

PPT
data structure and algorithm by bomboat_3
PPTX
Data Structure and Algorithms by Sabeen Memon03.pptx
PPTX
My lecture infix-to-postfix
PPTX
Stack_Application_Infix_Prefix.pptx
PDF
Applications of stack
PDF
Applications of Stack
PDF
1.3- infix-ti-postfix.pdf
PDF
Java Bytecodes by Example
PDF
Data structure and algorithm.(dsa)
PPT
Infix prefix postfix
PPT
Unit IV-infix to postfix and eval.ppt dsa
PPT
Arithmetic notation conversion infix to1
PPTX
Applicationofstack by Ali F.RAshid
PPT
Postfix Evaluations using Stack
PPT
Data structure lecture7
PPTX
Stacks in DATA STRUCTURE
PPTX
Lecture 6 data structures and algorithms
PPTX
Prefix, Infix and Post-fix Notations
PPTX
Implementation of stacks and queues in C
PDF
ECMAScript 6
data structure and algorithm by bomboat_3
Data Structure and Algorithms by Sabeen Memon03.pptx
My lecture infix-to-postfix
Stack_Application_Infix_Prefix.pptx
Applications of stack
Applications of Stack
1.3- infix-ti-postfix.pdf
Java Bytecodes by Example
Data structure and algorithm.(dsa)
Infix prefix postfix
Unit IV-infix to postfix and eval.ppt dsa
Arithmetic notation conversion infix to1
Applicationofstack by Ali F.RAshid
Postfix Evaluations using Stack
Data structure lecture7
Stacks in DATA STRUCTURE
Lecture 6 data structures and algorithms
Prefix, Infix and Post-fix Notations
Implementation of stacks and queues in C
ECMAScript 6
Ad

Recently uploaded (20)

PDF
How to run a consulting project- client discovery
PPTX
QUANTUM_COMPUTING_AND_ITS_POTENTIAL_APPLICATIONS[2].pptx
DOCX
Factor Analysis Word Document Presentation
PDF
Microsoft Core Cloud Services powerpoint
PDF
Capcut Pro Crack For PC Latest Version {Fully Unlocked 2025}
PPTX
A Complete Guide to Streamlining Business Processes
PDF
Optimise Shopper Experiences with a Strong Data Estate.pdf
PPTX
Database Infoormation System (DBIS).pptx
PDF
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
PPTX
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
PPTX
Topic 5 Presentation 5 Lesson 5 Corporate Fin
PDF
Transcultural that can help you someday.
PPTX
STERILIZATION AND DISINFECTION-1.ppthhhbx
PPTX
CYBER SECURITY the Next Warefare Tactics
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
PDF
Introduction to the R Programming Language
How to run a consulting project- client discovery
QUANTUM_COMPUTING_AND_ITS_POTENTIAL_APPLICATIONS[2].pptx
Factor Analysis Word Document Presentation
Microsoft Core Cloud Services powerpoint
Capcut Pro Crack For PC Latest Version {Fully Unlocked 2025}
A Complete Guide to Streamlining Business Processes
Optimise Shopper Experiences with a Strong Data Estate.pdf
Database Infoormation System (DBIS).pptx
REAL ILLUMINATI AGENT IN KAMPALA UGANDA CALL ON+256765750853/0705037305
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Acceptance and paychological effects of mandatory extra coach I classes.pptx
sac 451hinhgsgshssjsjsjheegdggeegegdggddgeg.pptx
01_intro xxxxxxxxxxfffffffffffaaaaaaaaaaafg
Topic 5 Presentation 5 Lesson 5 Corporate Fin
Transcultural that can help you someday.
STERILIZATION AND DISINFECTION-1.ppthhhbx
CYBER SECURITY the Next Warefare Tactics
Qualitative Qantitative and Mixed Methods.pptx
Market Analysis -202507- Wind-Solar+Hybrid+Street+Lights+for+the+North+Amer...
Introduction to the R Programming Language

Ds stack 03

  • 1. What is Stack ? A stack is a list of elements in which an element may be inserted or deleted only at one end, called the top of the stack. Stacks are sometimes known as LIFO (last in, first out). This means that last thing we added (pushed) is the first thing that gets pulled (popped) off . A stack is sequence of items that are accessible at only one end of the sequence.
  • 14. Infix to Postfix Infix Postfix A + B A B + 12 + 60 – 23 12 60 + 23 – (A + B)*(C – D ) A B + C D – * A ↑ B * C – D + E/F A B ↑ C*D – E F/+
  • 15. Infix to Postfix Note that the postfix form an expression does not require parenthesis. Consider ‘4+3*5’ and ‘(4+3)*5’. The parenthesis are not needed in the first but they are necessary in the second. The postfix forms are: 4+3*5 435*+ (4+3)*5 43+5*
  • 16. Evaluating Postfix Each operator in a postfix expression refers to the previous two operands. Each time we read an operand, we push it on a stack. When we reach an operator, we pop the two operands from the top of the stack, apply the operator and push the result back on the stack.
  • 17. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6
  • 18. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2
  • 19. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3
  • 20. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5
  • 21. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1
  • 22. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3
  • 23. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8
  • 24. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2
  • 25. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4
  • 26. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7
  • 27. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7
  • 28. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7 2 1 7 7 7,2
  • 29. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7 2 1 7 7 7,2 ↑ 7 2 49 49
  • 30. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7 2 1 7 7 7,2 ↑ 7 2 49 49 3 7 2 49 49,3
  • 31. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7 2 1 7 7 7,2 ↑ 7 2 49 49 3 7 2 49 49,3 + 49 3 52 52
  • 32. Evaluating Postfix Evaluate 6 2 3 + - 3 8 2 / + * 2 ↑ 3 + Input op1 op2 value stack 6 6 2 6,2 3 6,2,3 + 2 3 5 6,5 - 6 5 1 1 3 6 5 1 1,3 8 6 5 1 1,3,8 2 6 5 1 1,3,8,2 / 8 2 4 1,3,4 + 3 4 7 1,7 * 1 7 7 7 2 1 7 7 7,2 ↑ 7 2 49 49 3 7 2 49 49,3 + 49 3 52 52