C++ program that parses Infix Notation (usual mathematical expressions) to Reverse Polish Notation (Postfix notation) and then evaluates it.
- Infix : 2+3*6 | Postfix : 2 3 6 * +
- Infix : (2+3)*6 | Postfix : 2 3 + 6 *
- Infix : (-2-3)6 | Sanitized Infix : (0 -2 - 3) * 6
- Addition
- Subtraction
- Multiplication
- Division
- Absolute Value (denoted by the symbol m)
- Square Root (denoted by the symbol t)
- Sin, Cos, Tan (denoted by symbols s, c and t respectively)
- Power (denoted by the symbol ^)
- Modulus
- Create an instance of
InfixCalculator
which takes in the Infix string as a parameter - Call method
evalPostfix()
which return evaluated Postfix asstring
- Postfix value can be stored as a
List<String>
(depiction and not actual syntax) instead of astring
- Trigonometric values of negative numbers are not properly evaluated (that's what I think).
The code doesn't cover all the edge cases and it for the one using this library to find out what edge cases are missing.
- Sergei Lebedev (Data Structures and Algorithms lab in-charge)
- Introduction to Alorithms, CLRS , MIT Press
- Heineken Lager Beer