Infix and Postfix
Algorithm for Postfix Evaluation
- Create an empty stack called operandStack.
- Scan the string from left to right.
- If the token is an operand, convert it from a string to an integer and push the value onto the operand stack.
- If the token is an operator, *, /, +, or -, it will need two operands. Pop the operandStack twice. The first pop is the second operand and the second pop is the first operand. Perform the arithmetic operation. Push the result back on the operand stack.
- When the input expression has been completely processed, the result is on the stack. Pop the operand stack and return the value.