Note: Do not use spaces in expression. A+B/C or 4+5/3
not A + B / C or 4 + 5 / 3

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 :


Sr. no. Expression Stack Postfix

Algorithm used

Postfix

  • Step 1: Add ')' to the end of the infix expression
  • Step 2: Push '(' into the stack
  • Step 3: Repeat until each character in the infix notation is scanned
    • IF a(is encountered, push it on the stack
    • IF an operand (whetheradigit oracharacter) is encountered, add it postfix expression.
    • 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
    • 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 the same precedence orahigher precedence than O
      b. Push the operator 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 infix expression Step 1.
  • Step 3: Reverse the postfix expression to get the prefix expression