Você está na página 1de 1

LAB # 03

OBJECTIVE:
Stack Implementation

LAB TASKS
TASK 1

POSTFIX EVALUATION:
Use stack to solve this problem. The input for this problem is a valid postfix expression. Evaluate
that expression and display the result.

Algorithm for postfix evaluation:
The algorithm is simple:

Read in input.
If input is an operand, push on stack.
If input is an operator, pop top two operands off stack, perform operation, and place
result on stack.

Example: 3 4 5 * +

Push 3, 4, and then 5 on the stack.
Pop 5 and 4, perform multiplication, and push result.
Pop (5*4) and 3, perform addition, and push result.