Postfix Notation for Expressions
|
Infix notation Write the operator between the operands |
|
Postfix notation Write the
operator after the operands |
|
3 + 4 |
|
3 4 + |
|
3 / 2 |
|
3 2 / |
|
2 * (
3 + 4 ) |
|
2 3 4
+ * The +
operator follows its operands 3 and 4 The *
operator follows its operands 2 and (3 4 +) |
E.g. (
2 ( 3 4 + ) * ) is
equivalent to 2 3 4
+ *
|
Write the
infix expression A
+ B / C - 3 in postfix: A + B
/ C - 3 A + B C / - 3 A B C / + - 3 A B C / + 3 - |
|
Evaluate the
postfix expression 9
3 2 + 8 4 / + -: 9 3 2 + 8 4 / + - 9 5 8 4 / + - 9 5 2 + - 9 7 - 2 |
|
Write the
postfix expression A
7 D + * in infix: A 7 D
+ * A ( 7 + D ) * ( A * ( 7 + D ) ) |
Exercises
Write the following infix expressions in postfix:
1. A - 2 + B
2. ( A + 7 ) * ( B - 2 )
3. C + 7 * B
Evaluate the following postfix expressions:
4. 3 2 * 6 2 / +
5. 5 2 7 + 2 1 - + /
Write the following postfix
expressions in infix:
6. E F 7 - -
7. G H 2 * A / + 4 -