Algorithm for Postfix Expression Evaluator: 1. Initialize an operand stack. 2. I
ID: 3770216 • Letter: A
Question
Algorithm for Postfix Expression Evaluator:
1. Initialize an operand stack.
2. Input characters of postfix string from left to right ignoring white spaces.
3. IF character = operand THEN push it onto operand stack.
4. IF character = operator THEN pop operand stack twice and perform operation of recently read operator on both popped operands. Push the result onto the top of the stack.
5. IF there are no more characters to be read THEN pop the last number in the operand stack and display it as the final evaluated expression result.
I basically just need to convert POSTFIX to INFIX and i want to put in variables not numbers. (a through z)
Explanation / Answer
Algorithm of Postfix to Infix
1.While there are input symbol left
2. Read the next symbol from input.
3. If the symbol is an operand
Push it onto the stack.
4. Otherwise,
the symbol is an operator.
5. If there are fewer than 2 values on the stack
Show Error /* input not sufficient values in the expression */
6. Else
Pop the top 2 values from the stack.
Put the operator, with the values as arguments and form a string.
Encapsulate the resulted string with parenthesis.
Push the resulted string back to stack.
7. If there is only one value in the stack
That value in the stack is the desired infix string.
8. If there are more values in the stack
Show Error /* The user input has too many values */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.