This program evaluates mathematical expressions in prefix notation.
- Clone this repository:
git clone git@github.com:SegundoRP/prefix-notation-string.git
cd prefix-notation-string
- Run the script:
ruby prefix_notation_algorithm.rb
- Enter the expression in prefix notation. Example:
Please enter a prefix notation expression:
+ + 12 16 * 10 4
Output:
Result: 68
Input | Output |
---|---|
9 |
9 |
+ 1 2 |
3 |
+ + 1 2 30 |
33 |
+ + 12 16 * 10 4 |
68 |
- The program assumes that the input is always valid and is in correct prefix notation.
- No error handling is performed if the expression is invalid or contains operators without enough operands.
- Only positive integers and the operators
+
,-
,*
, and/
are supported.