From charlesreid1

Revision as of 05:57, 7 June 2017 by Admin (talk | contribs)

About

Postfix expressions:

  • expressions in which the operation being specified occurs after the two operands, in a nested way

Example: each postfix expression evaluates to 9.

5 4 + 
2 7 * 4 1 + -
1 1 + 1 1 + + 1 1 + 1 1 + + +

Stacks

Postfix expressions can be evaluated by pushing the expressions onto a stack, where the stack deals with expressions. Expressions can consist of a single node (a number), or two expressions and an operator (making the expression definition recursive - like a tree).

In terms of stacks, we can push digits onto the stack UNTIL we reach a symbol, then apply the symbol to the next two expressions on the stack, turn the result into an expression, and push the result expression onto the stack.