Infix to Postfix Visualizer

What is Postfix Notation?

Postfix notation (also called Reverse Polish Notation) is a way of writing expressions where the operator comes after the operands.

For example, the infix expression 3 + 4 becomes 3 4 + in postfix.
It removes the need for parentheses by making operator precedence explicit through position.

Infix to Postfix Conversion Steps

  1. Initialize an empty stack and an empty output string.
  2. Scan the infix expression from left to right.
  3. If the element is an operand, add it to the output.
  4. If the element is a '(', push it onto the stack.
  5. If the element is a ')', pop from the stack and add to output until '(' is encountered.
  6. If the element is an operator, pop from the stack all operators with higher or equal precedence, then push the current operator.
  7. After scanning, pop all remaining operators from the stack.

Example:
Infix: (A + B) * (C - D)
Step 1: Push '(' → Stack: [ '(' ], Output: ''
Step 2: Add 'A' → Output: 'A'
Step 3: Push '+' → Stack: [ '(', '+' ]
Step 4: Add 'B' → Output: 'A B'
Step 5: Pop until '(' → Stack: [ ], Output: 'A B +'
Step 6: Continue similarly for the rest → Final Postfix: A B + C D - *

Operator Precedence Table

OperatorMeaningPrecedence
( )ParenthesesHighest
^Exponentiation2
* /Multiplication / Division3
+ -Addition / Subtraction4 (Lowest)

Note: Higher precedence means the operation will happen first. When operators have equal precedence, they are evaluated left-to-right (except for exponentiation which is right-to-left).

Visualize the conversion from infix to postfix notation

Conversion Status

Enter an infix expression and click Convert

Stack

Stack is empty

Output

Output will appear here

Explore other conversions