Please help me with formulas for converting algebraic expressions from infix forms to postfix and prefix ones with the inclusion of expressions with different priorities and brackets.
- Polish record?) Wikipedia has an algorithm - eri
- Himself once wrote a calculator. I advise you to read about the Polish record / notation. Dijkstra's algorithm for translation into Polish notation. - Kozinetov
|
1 answer
For postfix: sorting station algorithm (wiki)
There is a detailed description, and the first link is an example of java.
For prefix:
- We have the input formula in infix form: a + b / (cd);
- Let's rewrite the formula from right to left: (dc) / b + a;
- We use the postfix translation algorithm, we get: dc-b / a +;
- We rewrite the resulting formula from right to left, we obtain the formula in the prefix notation: + a / b-cd.
Found here .
|