SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Reverse
Polish
Notation
BEDMAS
BIDMAS
BODMAS
PEMDAS
6,2/1,2+*
                *
    /                     +
6       2           1          2
            /           6,2,1,2,+*/

                    *
                         +

6       2           1         2
Evaluating RPN
• Uses a stack and two simple rules. Reading
  left to right …….
• 1. If a value appears next in the
  expression, push this value on to the stack.
• 2. If an operator appears next, pop two items
  from the top of the stack and push the result
  of the operation on to the stack.
Reverse Polish Notation Examples

    7,4+3-        7+4-3

    1,2*3+        1*2+3

    1,2+3*        (1+2) *3

    5,9,2*+       5+9*2

    1,2*3,4*+     1*2+3*4
Converting from infix to postfix
         ‘Shunting yard algorithm’

• Read each character                  • Calculator - another
• If its an operand, add it to
  the output
• If it’s an operator then
   – If there’s a higher BODMAS
     priority operator at the top of
     the stack, pop it
   – Push it on the stack
• At the end, pop everything
  off the operator stack
Reverse polish notation

Weitere ähnliche Inhalte

Was ist angesagt?

Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxAlbin562191
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...vtunotesbysree
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure Janki Shah
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1Kumar
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8sumitbardhan
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - NotesOmprakash Chauhan
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structureSajid Marwat
 

Was ist angesagt? (20)

Multiprocessor system
Multiprocessor system Multiprocessor system
Multiprocessor system
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptxPolynomial reppresentation using Linkedlist-Application of LL.pptx
Polynomial reppresentation using Linkedlist-Application of LL.pptx
 
stack presentation
stack presentationstack presentation
stack presentation
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Double ended queue
Double ended queueDouble ended queue
Double ended queue
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
SOLUTION MANUAL OF COMPUTER ORGANIZATION BY CARL HAMACHER, ZVONKO VRANESIC & ...
 
Red black tree
Red black treeRed black tree
Red black tree
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Stack
StackStack
Stack
 
AVL Tree in Data Structure
AVL Tree in Data Structure AVL Tree in Data Structure
AVL Tree in Data Structure
 
Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)Balanced Tree (AVL Tree & Red-Black Tree)
Balanced Tree (AVL Tree & Red-Black Tree)
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
 
Stack
StackStack
Stack
 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8358 33 powerpoint-slides_8-linked-lists_chapter-8
358 33 powerpoint-slides_8-linked-lists_chapter-8
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 

Mehr von grahamwell

Excel =if function
Excel =if functionExcel =if function
Excel =if functiongrahamwell
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average grahamwell
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?grahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch developgrahamwell
 
The software story
The software storyThe software story
The software storygrahamwell
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphicsgrahamwell
 
Database field types
Database field typesDatabase field types
Database field typesgrahamwell
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and typesgrahamwell
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and typesgrahamwell
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9grahamwell
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your projectgrahamwell
 
The rail fence
The rail fenceThe rail fence
The rail fencegrahamwell
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryptiongrahamwell
 
Server side scripts
Server side scriptsServer side scripts
Server side scriptsgrahamwell
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and controlgrahamwell
 

Mehr von grahamwell (20)

Pseudocode
PseudocodePseudocode
Pseudocode
 
Excel =if function
Excel =if functionExcel =if function
Excel =if function
 
Excel Min max-average
Excel Min max-average Excel Min max-average
Excel Min max-average
 
What is binary and why do we use it?
What is binary and why do we use it?What is binary and why do we use it?
What is binary and why do we use it?
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
Introduction to touch develop
Introduction to touch developIntroduction to touch develop
Introduction to touch develop
 
The software story
The software storyThe software story
The software story
 
Turtle graphics
Turtle graphicsTurtle graphics
Turtle graphics
 
Database field types
Database field typesDatabase field types
Database field types
 
Databases 101
Databases 101Databases 101
Databases 101
 
Kodu controls
Kodu controlsKodu controls
Kodu controls
 
Pascal names and types
Pascal names and typesPascal names and types
Pascal names and types
 
Python part two names and types
Python part two names and typesPython part two names and types
Python part two names and types
 
Abstraction - Year 9
Abstraction - Year 9Abstraction - Year 9
Abstraction - Year 9
 
Thinking about your project
Thinking about your projectThinking about your project
Thinking about your project
 
The rail fence
The rail fenceThe rail fence
The rail fence
 
Lesson 1
Lesson 1Lesson 1
Lesson 1
 
Rsa encryption
Rsa encryptionRsa encryption
Rsa encryption
 
Server side scripts
Server side scriptsServer side scripts
Server side scripts
 
Revision topic 1 sensors and control
Revision topic 1 sensors and controlRevision topic 1 sensors and control
Revision topic 1 sensors and control
 

Reverse polish notation

  • 3. 6,2/1,2+* * / + 6 2 1 2 / 6,2,1,2,+*/ * + 6 2 1 2
  • 4. Evaluating RPN • Uses a stack and two simple rules. Reading left to right ……. • 1. If a value appears next in the expression, push this value on to the stack. • 2. If an operator appears next, pop two items from the top of the stack and push the result of the operation on to the stack.
  • 5. Reverse Polish Notation Examples 7,4+3- 7+4-3 1,2*3+ 1*2+3 1,2+3* (1+2) *3 5,9,2*+ 5+9*2 1,2*3,4*+ 1*2+3*4
  • 6. Converting from infix to postfix ‘Shunting yard algorithm’ • Read each character • Calculator - another • If its an operand, add it to the output • If it’s an operator then – If there’s a higher BODMAS priority operator at the top of the stack, pop it – Push it on the stack • At the end, pop everything off the operator stack