9 2 4 5 9 2 4 5 numbers 9 2 x l r 4 while not end of

This preview shows page 43 - 57 out of 106 pages.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 2 X = * L = R = 4 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, > R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Ah! X is an operator, pop the top element save into R
Image of page 43

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 X = * L = 2 R = 4 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers > L = POP Numbers Evaluate L X R; PUSH result onto Numbers Top element is removed and saved into L
Image of page 44
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 8 X = * L = 2 R = 4 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers > Evaluate L X R; PUSH result onto Numbers Push the result of L X R, 2 × 4 = 8 , onto the stack
Image of page 45

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 8 X = 5 L = 2 R = 4 While not end-of-expression do: > Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Read X
Image of page 46
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 8 5 X = 5 L = 2 R = 4 While not end-of-expression do: Read X > If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Push X
Image of page 47

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 8 5 X = - L = 2 R = 4 While not end-of-expression do: > Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Read X
Image of page 48
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 8 X = - L = 2 R = 5 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, > R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Remove the top element and save it into R
Image of page 49

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 X = - L = 8 R = 5 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers > L = POP Numbers Evaluate L X R; PUSH result onto Numbers Remove the top element and save it into L
Image of page 50
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 3 X = - L = 8 R = 5 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers > Evaluate L X R; PUSH result onto Numbers Push the result of L X R, 8 - 5 = 3 , onto the stack
Image of page 51

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 3 X = / L = 8 R = 5 While not end-of-expression do: > Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers Read X
Image of page 52
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [9 X = / L = 8 R = 3 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, > R = POP Numbers L = POP Numbers Evaluate L X R; PUSH result onto Numbers R = POP Numbers.
Image of page 53

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [ X = / L = 9 R = 3 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers > L = POP Numbers Evaluate L X R; PUSH result onto Numbers L = POP Numbers.
Image of page 54
9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [3 X = / L = 9 R = 3 While not end-of-expression do: Read X If X isNumber, PUSH X onto Numbers If X isOperator, R = POP Numbers L = POP Numbers > Evaluate L X R; PUSH result onto Numbers Push L X R, 9 ÷ 3 = 3 , onto the stack sur la pile.
Image of page 55

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [3 X = / L = 9 R = 3
Image of page 56
Image of page 57
You've reached the end of this preview.
  • Spring '10
  • Samaan
  • Reverse Polish notation, School of Information Technology and Engineering, POP Numbers

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern