Algorithm for Evaluation of Postfix Expression

June 17, 2010 No Comments » Hits : 105






Algorithm for Evaluation of Postfix Expression

Initialize(Stack S)x = ReadToken();  // Read Tokenwhile(x){     if ( x is Operand )         Push ( x ) Onto Stack S.

     if ( x is Operator )            {            Operand2 = Pop(Stack S);            Operand2 = Pop(Stack S);            Evaluate (Operand1,Operand2,Operator x);            }

     x = ReadNextToken();  // Read Token}

Live Example : 5 3 2 + 8 * +