In infix notation, operators are placed between their operands. This is the most common way mathematical expressions are written in standard mathematical notation. For example:
- Addition: 2 + 3
- Subtraction: 5 - 2
- Multiplication: 4 * 6
- Division: 8 / 2
Infix notation follows the standard order of operations (PEMDAS/BODMAS), where parentheses can be used to specify the desired order of evaluation.
In postfix notation, operators are placed after their operands. To evaluate a postfix expression, you start from the left and move to the right, performing the operation when you encounter an operator after its operands. For example:
- Addition: 2 3 +
- Subtraction: 5 2 -
- Multiplication: 4 6 *
- Division: 8 2 /
- Fork the repo and run locally on any IDE.
- Click here to run
The stack data structure is required to convert any infix notation to postfix notation, it stores the operators according to their associativity and pops accordingly to generate desired results.
If you want to know more about data structure check out this repo