Infixtopostfix code is not working
hi @kundankumarsports2, in the infix expression you can have brackets but in postfix expression we don’t have any brackets so the length is not same as that of infix for postfix expression , also there are some cases you are missing you can refer to below algo for that .
note: use stl stack for stack based questions , it will save your time
let me provide u the algo in
Algorithm
- Scan the infix expression from left to right.
- If the scanned character is an operand, output it.
- Else,
……3.1 If the precedence of the scanned operator is greater than the precedence of the operator in the stack(or the stack is empty or the stack contains a ‘(‘ ), push it.
……3.2 Else, Pop all the operators from the stack which are greater than or equal to in precedence than that of the scanned operator. After doing that Push the scanned operator to the stack. (If you encounter parenthesis while popping then stop there and push the scanned operator in the stack.)- If the scanned character is an ‘(‘, push it to the stack.
- If the scanned character is an ‘)’, pop the stack and and output it until a ‘(‘ is encountered, and discard both the parenthesis.
- Repeat steps 2-6 until infix expression is scanned.
- Print the output
- Pop and output from the stack until it is not empty.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.