Question: Write a C program that evaluates a postfix expression, such as 6 2 + 5 * 8 4 / - The program should read a
Write a C program that evaluates a postfix expression, such as 6 2 + 5 * 8 4 / -
The program should read a postfix expression consisting of single digits and operators into a character array. Using the stack functions implemented earlier in this project (project-1), the program should scan the expression and evaluate it. The algorithm can be as follows:
1) Append the null character ('\0') to the end of the postfix expression. When the null character is encountered, no further processing is necessary.
2) While '\0' has not been encountered, 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 computers character set minus the value of '0' in the computers 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.
3) When the null character is encountered in the expression, pop the top value of the stack. that will be a result of the postfix expression.
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
