The problem. Given a valid prefix expression (operator before its operands), convert it to postfix (operator after its operands). Operands are single letters or digits; operators are + - * / ^. For example, *+AB-CD becomes AB+CD-*.
Input: "*+AB-CD" Output: "AB+CD-*"
Input: "*-A/BC-/AKL" Output: "ABC/-AK/L-*"
Input: "A" Output: "A"Neither prefix nor postfix needs brackets, so no brackets appear anywhere. Each operator just has to move from before its two operands to after them — and its operands may themselves be whole expressions.
Free account
Sign up to read the rest of this lesson: 5 more sections, 3 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come