Question: 1 9 . 1 3 ( Postfix Evaluation ) Write a program that evaluates a valid postfix expression such as 6 2 + 5 *

19.13(Postfix Evaluation) Write a program that evaluates a valid postfix expression such as 62+5*84/-The program should read a postfix expression consisting of digits and operators into a string.Using modified versions of the stack functions implemented earlier in this chapter, the program should scan the expression and evaluate it. The algorithm is as follows:1) While you have not reached the end of the string, read the expression from left to right.If the current character is a digit,Push its integer value onto the stack (the integer value of a digit character is its value in the computer's character set minus the value of 'O' in the computer's character set).Otherwise, if the current character is an operator,Pop the two top elements of the stack into variables x and y.Calculate y operator x.Push the result of the calculation onto the stack.2) When you reach the end of the string, pop the top value of the stack. This is the result of the postfix expression.(Note: In Step 2 above, if the operator is '/', the top of the stack is 2 and the next element in the stack is 8, then pop 2 into x, pop 8 into y, evaluate 8/2 and push the result, 4, back onto the stack.This note also applies to operator '-.] The arithmetic operations allowed in an expression are+ addition- subtraction

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!