Note: Do not use spaces in expression. A+B/C or 4+5/3 not A + B / C or
4 +
5 / 3
Updated (26 Feb 2023)
Infix -> Postfix & Prefix
This is a simple infix to prefix or postfix Converter.
Enter the Infix expression below in box and press Convert
Postfix : | Prefix :
By Raj
Sr. no.
Expression
Stack
Postfix
Algorithm used
Postfix
Step 1: Add ")" to the end of the infix expression
Step 2: Push "(" onto the stack
Step 3: Repeat until each character in the infix notation is scanned
3.1: IF a "(" is encountered, push it on the stack
3.2: IF an operand ( whether a digit or a character) is encountered, add it
postfix
expression.
3.3: IF a ")" is encountered, then
a. Repeatedly pop from stack and add it to the postfix expression until a
"(" is encountered.
b. Discard the "(". That is, remove the(from stack and do not add it to the
postfix expression
3.4: IF an operator O is encountered, then
a. Repeatedly pop from stack and add each operator ( popped from the stack)
to the postfix expression which has equal or higher precedence
than O
b. Push the operator O to the stack.
[END OF IF]
Step 4: Repeatedly pop from the stack and add it to the postfix expression until the
stack is empty
Step 5: EXIT
Prefix
Step 1: Reverse the infix string. Note that while reversing the string you must
interchange left and right parentheses.
Step 2: Obtain the postfix expression of the expression obtained from Step 1
using the above given postfix algorithm with slight change in Step
3.4
IF an operator O is encountered, then
a. Repeatedly pop from stack and add each operator ( popped from the stack)
to the postfix expression which has equal or higher precedence
than O
Step 3: Reverse the postfix expression to get the prefix expression