Question: Some calculators ( notably those from Hewlett - Packard ) use a system of writing mathematical expressions known as Reverse Polish Notation ( RPN )
Some calculators notably those from HewlettPackard use a system of writing mathematical expressions known as Reverse Polish Notation RPN In this notation, operators are placed after their operands instead of between their operands. For example, would be written in RPN and would be written RPN expressions can easily be evaluated using a stack. The algorithm involves reading the operators and operands in an expression from left to right, performing the following actions:
When an operand is encountered, push it onto the stack.
When an operator is encountered, pop its operands from the stack, perform the operation on those operands and then push the result onto the stack.
Write a c program that evaluates RPN expressions. The operands will be singledigit integers, The operators are and The operator causes the top stack item to be displayed; afterwards, the stack is cleared and the user is prompted to enter another expression. The process continues until the user enters a character that is not an operator or operand:
Enter an RPN expression: Value of expression: Enter an RPN expression: Value of expression: Enter an RPN expression: q
If the stack overflows, the program will display the message Expression is too complex and terminate. If the stack underflows because of an expression such as the program will display the message Not enough operands in expression and terminate. Hints: Incorporate the stack code from Section into your program. Use scanfc &ch to read the operators and operands.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
