Problem

Reverse Polish Notation (RPN), or postfix notation, is a format to .specify mathematical e...

Reverse Polish Notation (RPN), or postfix notation, is a format to .specify mathematical expressions. In RPN, the operator comes after the operands instead of the normal format in which the operator is between the operands (this is called infix notation). Starting with an empty stack, a RPN calculator can be implemented with the following rules:

■If a number is input, push it on the stack.

■If “+” is input, then pop the last two operands off the stack, add them, and push the result on the stack.

■If “-” is input then pop valuel, pop value2, then push value2- valuel on the stack.

■If “*” is input, then pop the last two operands off the stack, multiply them, and push the result on the stack

■If “/” is input them pop valuel, pop value2, dien push value2/ valuel on the stack

■If “q” is input, then stop inputting values, print out the top of die stack, and exit the program

Modify the Stack class given in Section 13.2 to store integers instead of characters. Use the modified stack to implement a RPN calculator. Output an appropriate error message if there are not two operands on the stack when given an operator. Here is a sample input and output that  is equivalent to ((10 - (2 + 3)) * 2)/5:

10

2

3

+

-

2

*

5

/

q

The top of the stack is: 2

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 13
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT