(Latest Revision: Tue Oct 31 22:55:00 PST 2000 ) evalPostFix.alg

evalPostFix.alg


Inputs: Example:

X A B - Y Z + * -
The pseudo code algorithm for evaluating the expression is:


FOR (each character Ch in the string)
{
  IF    (Ch is an operand)
  THEN  Push value that operand Ch represents onto the stack
  ELSE /* Ch is an operator named Op */
  {     // evaluate and push the result
    Operand2 = top of stack  /* top not removed. */
    Pop the stack            /* Pop removes top. */
    Operand1 = top of stack
    Pop the stack
    Result = Operand1 Op Operand2
    Push Result onto stack 
  }
}