#C12837. Infix to Postfix Conversion
Infix to Postfix Conversion
Infix to Postfix Conversion
You are given a mathematical expression in infix notation where tokens (operands and operators) are separated by spaces. Your task is to convert the given infix expression to its corresponding postfix notation (also known as Reverse Polish Notation).
The expression may include non-negative integers, the binary operators +
, -
, *
, /
, and parentheses (
and )
.
Recall that the operator precedence is given by:
\( +, -: 1 \) and \( *, /: 2 \).
You can use the shunting-yard algorithm to achieve the conversion.
inputFormat
A single line containing an infix expression with tokens separated by spaces. For example: "3 + 4 * 2 / ( 1 - 5 )".
outputFormat
A single line representing the postfix notation of the given expression. For example: "3 4 2 * 1 5 - / +".## sample
3 + 4
3 4 +