Infix to postfix

can u please xplain why my code isn’t working

Have debugged your code, but the implementation is still not correct.
Your code which i have corrected:

Proper implementation for this problem:


Run this on your compiler as there is some issue with online ide right now.

but if am not giving ‘^’ in input why does it create a problem. I know its not the correct approach as it don’t work for all cases . but still i want to know why ‘^’ is creating problem

Problem is not because of only ^ , as giving precedence value is also necessary. Try for this input to, a+b*(cd-e)(f+g*h)-i your code will still not work. Just dry run the code i have given it to you, as there are side cases too. Which you haven’t considered. Rest the logic you have applied is right.

st.top() != ‘N’
why are we writing this … can’t we write !st.empty()

Yes you can do that also, what’s there in the code is that it did add ‘N’ in stack as of a dummy element and have checked if top is equal to N or not. Also if you would use !st.epmty() then it would be more correct as the output won’t be having ‘N’ in it. So yes you can do !st.empty() instead of st.top() != ‘N’