1.

Write an algorithm to evaluate postfix expression.

Answer»

Step 1: Start

Step 2: Check all symbols from left to right and repeat steps 3 & 4 for each symbol of expression ‘E’ until all symbols are over.

(i)  If the symbol is an operand, push it onto a stack.

(ii) If the symbol is an operator then:

(iii) Pop the top two operands from the stack and apply an operator in between them.

(iv) Evaluate the expression and place the result back on the stack.

Step 3: Set result equal to a top element on the stack.

Step 4: Stop



Discussion

No Comment Found