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

• Notes
• 106

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

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
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

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
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

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
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

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
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

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
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.

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.
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.

Subscribe to view the full document.

9 / ((2 * 4) - 5) = 9 2 4 * 5 - / ^ Numbers = [3 X = / L = 9 R = 3
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

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern