The problem. Given a valid postfix expression (operator after its operands), convert it to prefix (operator before its operands). Operands are single letters or digits; operators are + - * / ^. For example, AB+CD-* becomes *+AB-CD.
Input: "AB+CD-*" Output: "*+AB-CD"
Input: "ABC/-AK/L-*" Output: "*-A/BC-/AKL"
Input: "ABC*+DE/-" Output: "-+A*BC/DE"This is the mirror image of Prefix to Postfix. Postfix is read naturally from the left: when an operator appears, its two operands are the two most recent finished pieces — a stack's top two items.
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