🔄 Infix to Postfix Converter

Convert mathematical expressions for easier compiler evaluation

🎯 Problem: Infix → Postfix Conversion

Hi! I'm Teju 👋 Compilers evaluate expressions faster in postfix (Reverse Polish Notation) because no parentheses or precedence rules are needed.

Infix: A + B × C → Postfix: A B C × +

Goal: Convert infix expression (with parentheses) to postfix

Operators: + − × / ^ ( )

Operands: Single uppercase letters (A-Z)

⚙️ Shunting Yard Algorithm (Stack-Based)

We use a stack to manage operators and parentheses.

  1. Scan expression from left to right
  2. If operand (A-Z) → add to output
  3. If '(' → push to stack
  4. If ')' → pop stack to output until '(' found
  5. If operator (+−×/^):
    • While stack top has ≥ precedence → pop to output
    • Push current operator
  6. At end → pop all remaining operators to output

Precedence: ^ (highest) → × / → + − (lowest)
Left-associative except ^ (right-associative)

🎮 Interactive Demo

Enter an infix expression and click Convert to see the transformation...

📥 Infix Expression

🗼 Operator Stack

Empty Stack

📤 Postfix Output