
Infix to Postfix Conversion
You are provided with a string EXP
which represents a valid infix expression. Your task is to convert this given infix expression into a postfix expression.
Explanation:
An infix expression is of the form a op b
where the operator is placed between the operands. Conversely, a postfix expression is of the form a b op
where the operator is placed after the operands.
Input:
The first line of input contains an integer ‘T’ representing the number of test cases. Each test case contains one string ‘EXP’, a valid infix expression.
Output:
For each test case, output the corresponding postfix expression on a new line.
Example:
Input:
EXP = ‘3+4*8’
Output:
3 4 8 * +
Constraints:
1 <= T <= 10
1 <= N <= 5000
where N is the length ofEXP
- The expression contains digits, lowercase English letters, parentheses
()
, and operators+, -, *, /, ^
- Time Limit: 1 sec
Note:
You are not required to print anything. Implement the function as specified.

AnswerBot
7d

Convert infix expression to postfix expression.
Use a stack to keep track of operators and operands.
Follow the rules of precedence for operators.
Handle parentheses by pushing them onto the stack.
Pop op...read more

Help your peers!
Add answer anonymously...
Popular interview questions of Software Developer Intern
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app