Backwards Scan
Because Prefix notation puts the operator before the operands, we must scan from Right to Left to hit the operands first.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Converting Prefix back to Infix requires reading the string backwards and wrapping elements in parentheses as they are joined.
Because Prefix notation puts the operator before the operands, we must scan from Right to Left to hit the operands first.
Because we are scanning backwards, the FIRST popped element is `val1` (the left operand) and the SECOND popped element is `val2` (the right operand).
As always, the stack stores intermediate string chunks wrapped in `()`. When the loop finishes, the one remaining string is the full Infix expression.