Write an Algorithm to evaluate a postfix notation.

This is an Algorithm to evaluate of a postfix notation.

/* Reading of expression takes place from left to right */ 
1. Read the next element     /* first element for the first time */ 
2. if element is operand 
    then push the element in the stack 
3. if element is operator then 
{

pop two operands from the stack 
/* pop one operand in case of not operator */ 
evaluate the expression formed by the two operands and the operator push the result of the expression in the stack 
}
4. if no-more-elements then pop the result 
else 
go to step 1

Leave a Comment