#C14089. Infix to Postfix Conversion
Infix to Postfix Conversion
Infix to Postfix Conversion
This problem requires you to convert an infix mathematical expression to its equivalent postfix notation (also called Reverse Polish Notation, RPN). You will implement an algorithm based on the shunting-yard method which takes into account the operator precedence and associativity.
Consider the following operator precedence:
- \(+\) and \(-\) have the lowest precedence (1).
- \(*\) and \(/\) have higher precedence (2).
- \(^\) has the highest precedence (3) and is right-associative.
The input expression may include spaces which should be ignored. Parentheses \((\) and \()\) are used to override the default precedence rules.
Your task is to output the postfix expression as a string.
inputFormat
The input consists of a single line containing the infix expression. The expression can include digits (0-9), the operators +
, -
, *
, /
, ^
, parentheses ( )
and arbitrary spaces.
outputFormat
Output the expression converted to postfix (Reverse Polish Notation) with no spaces.
## sample3+4
34+
</p>