July 2018
Beginner
202 pages
5h 4m
English
Scenario
We are used to writing mathematical expressions in the form of 1 + 2 * 3. This type of notation is called an infix. Using infix notation, an operator is always in between two operators. There is a different notation called postfix, where the operator is after the operands. Examples of such expressions are shown in the following table:
| Infix expression | Postfix expression |
| 1 + 2 | 1 2 + |
| 1 + 2 * 3 | 1 2 3 * + |
| (1 + 2) * 3 | 1 2 + 3 * |
| 5 + 4 / 2 * 3 | 5 4 2 / 3 * + |
Aim
Implement an algorithm that accepts a postfix string, evaluates it, and returns the result.
Prerequisites
Read now
Unlock full access