Language: EN FI

Exercises > Postfix evaluation

These exercises demonstrate the content of the ByTheMark service. These are meant for private individuals for learning data structures and algorithms. If you want to try out more content, you can register to the ByTheMark Personal free of charge.

Infix expressions are often translated into postfix form in which the operators appear after their operands (e.g., 3*(2+4) would be 3 2 4 + *). The task is to evaluate a postfix expression with stack.

This is a tutorial exercise in which you can test your browser environment. See the instructions tab for more information.

1. read postfix expression token by token
2.   if the token is an operand, push it 
     into the stack
3.   if the token is a binary operator, 
3.1    pop the two top most operands 
       from the stack
3.2    apply the binary operator with the 
       two operands
3.3    push the result into the stack
4. finally, the value of the whole postfix 
   expression remains in the stack

  Last modified Tue Mar 01 20:54:04 EET 2011