Postfix to Infix Visualization & Animation

Converts postfix to infix by wrapping each operator application in parentheses using a stack; O(n).

## What is it? Convert a postfix expression (e.g. `AB+C*`) back to infix notation (e.g. `(A+B)*C`). Parentheses must be added to preserve the correct operator precedence. ## How it works - Scan postfix left to right using a stack - **Operand** → push to stack - **Operator** → pop two operands (`op2`, then `op1`), form `(op1 operator op2)` with parentheses, push the result back - At the end, the stack holds the infix expression ## When to use - Human-readable expression conversion - Displaying compiler intermediate representation in a readable form ## Key Points - Always wrap in parentheses when forming a sub-expression to avoid ambiguity - Pop order matters: second pop is `op1` (left operand), first pop is `op2` (right operand) - O(n) time and space

Category: algorithms

Difficulty: intermediate

Time Complexity: O(n)

Space Complexity: O(n)

Postfix to Infix

intermediate

Converts postfix to infix by wrapping each operator application in parentheses using a stack; O(n).

Init
empty
Stack
i
a
[0]
b
[1]
*
[2]
c
[3]
+
[4]
Current character (i)
Being popped from stack
Combined / result
Stable stack entry
Initialize: postfix="ab*c+". Scan left to right, build infix strings on stack.