Postfix Expressions: Difference between revisions
From charlesreid1
(Created page with "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. <pr...") |
No edit summary |
||
| Line 1: | Line 1: | ||
==About== | |||
Postfix expressions: | Postfix expressions: | ||
* expressions in which the operation being specified occurs after the two operands, in a nested way | * expressions in which the operation being specified occurs after the two operands, in a nested way | ||
| Line 15: | Line 17: | ||
1 1 + 1 1 + + 1 1 + 1 1 + + + | 1 1 + 1 1 + + 1 1 + 1 1 + + + | ||
</pre> | </pre> | ||
==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. | |||
Revision as of 05:57, 7 June 2017
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.