Evaluation of Postfix Expression

Evaluation of Postfix Expression

Algorithm:
  • Create stack to hold operands and result
  • Iterate String from start to end
    • If currentCharacter is digit then,
      • stack.push(currentCharacter)
    • Else
      • int operand1 = stack.pop
      • int operand2 = stack.pop
      • int result = operand1 currentCharacter operand2
      • stack.push(result)
  • return stack.pop

Latest Source Code:
Github: PostfixExpressionEvaluation.java


Output:

2 3 1 * + 9 - = -4

Author: Hrishikesh Mishra