Evaluation of Postfix Expression
Procedure to evaluate a postfix expression using stack.
Procedure :
Iterate through each character of the given postfix expression.
If the character is an operand (0 to 9), push it to stack after properly typecasting into integer value from char value by subtracting 48.
If the character is an operator, pop 2 items from the stack. The element to the popped will be num2 and the next element will be num1.
Evaluate the operation using switch case.
Push the result of evaluation to stack.
The result will be at stack top after the whole process.
C Program :
Contributed by Nitin Ranganath
Last updated