Write an algorithm to evaluate a postfix expression

Write an algorithm to evaluate a postfix expression

1.  opndstack = empty stack

2.  Scan one char at a time from right to left in string.

3.  If scan char is operand, push it in stack.

4.  If scan char is operator, pop opnd1, opnd2 and perform the operation specified by the operator. Push the result into stack.

5.  Repeat step 2, 3 and 4 until input prefix strings end.

6. Pop opndstack and display, which is required value of given expression.

Evaluate the following postfix expression abc +*de/-  where a = 5, b = 6,c = 2, d = 12, e = 4

Leave a Reply

Your email address will not be published. Required fields are marked *