#C7423. Infix to Postfix Conversion
Infix to Postfix Conversion
Infix to Postfix Conversion
Given an algebraic expression in infix notation, convert it to its equivalent postfix notation (Reverse Polish Notation). The expression consists of uppercase letters (operands) and the operators +, -, *, /, ^ along with parentheses ( ). The conversion should correctly handle operator precedence and associativity. In particular, the operators satisfy the following:
- Precedence: \(+, -\) have the lowest precedence, \(*, /\) have higher precedence, and \(^\) has the highest precedence.
- Associativity: \(+, -, *, /\) are left-associative, while \(^\) is right-associative.
For example:
- \(A+B\) converts to \(AB+\)
- \(A+(B*C)\) converts to \(ABC*+\)
- \((A-B/C)*(A/K-L)\) converts to \(ABC/-AK/L-*\)
- \(A+B*C-D/E\) converts to \(ABC*+DE/-\)
inputFormat
A single line containing the infix expression. The expression will consist of uppercase alphabets (operands), the operators +, -, *, /, ^, and parentheses ( ).
outputFormat
A single line containing the postfix conversion of the given infix expression.## sample
A+B
AB+
</p>