Algorithm to convert Infix to Prefix using STACK:
- Reverse the expression string.
- Read next element in the input expression.
- If it is an operand, output it.
- If it is a closing parenthesis, push on to the Stack.
- If it is an operator, then
- If the Stack is empty, push operator on Stack
- If the Top of stack is closing parenthesis, push operator on to the Stack.
- If the operator has “same or higher priority” than top of the Stack, push operator on to the Stack else Pop operator from the Stack and output it, repeat Step 5.
- If the is an Opening parenthesis, pop operators from stack and output them until closing parenthesis is encountered. POP and discard closing parenthesis.
- If there is more input go to step 2.
- If no more input, un stack all operators and output.
- Reverse Output expression that is Prefix





