Infix to Postfix Conversion

Convert a given infix expression, represented as a string EXP, into its equivalent postfix expression.

Explanation:

An infix expression is formatted as a op b where the operator is placed between operands. A postfix expression is formatted as a b op where the operator follows the operands.

For more details on infix and postfix expressions, refer to these links: Infix Notation and Postfix Notation.

Input:

The first line of input contains an integer 'T' denoting the number of test cases to run. Each test case consists of a single line containing a string 'EXP', which is a valid infix expression.

Output:

For each test case, print the corresponding postfix expression of the given infix expression. Each result should be printed on a new line.

Example:

Input:
EXP = '3+4*8'
Output:
3 4 8 * +
Explanation:

In the given example, multiplication is performed before addition, resulting in the postfix expression 3 4 8 * +.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 5000, where 'N' is the length of 'EXP'
  • The expression can contain digits, lowercase English letters, and the characters ‘(’, ‘)’, ‘+’, ‘-’, ‘*’, ‘/’, ‘^’.
  • Time Limit: 1 sec
Note:
You are not required to print anything; the function implementation will handle the output.
AnswerBot
1d

Convert infix expression to postfix expression by following operator precedence rules.

  • Use a stack to keep track of operators and operands while converting infix to postfix.

  • Follow the precedence rules ...read more

Help your peers!
Add answer anonymously...
Oracle Financial Services Software Associate Consultant Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter