I am a class 12 student from ISC 2022 batch, and this is my first question on Stack Overflow.
Recently this problem has been confusing me a lot, and I am finding different answers in the internet.
How do we convert an expression from infix to prefix in Java? For example, if the expression is (X+Y)/(Z*W/V), what is it's equivalent prefix expression?
My doubt focuses on the question that if while scanning, if incoming operator is of SAME precedence as that of top of the stack (TOS), then should we push it?
Or should we pop the TOS and check incoming operator with next TOS?
My computer teacher has taught us the latter, whereas in several sources like geeksforgeeks and javatpoint, I am finding the former method.
Please could someone clarify my doubt once and for all?