---
# System prepended metadata

title: PID-480

---

To convert the infix expression $$A-B/(C*D^E)$$ to postfix, we can use the following algorithm [3]:

1. Create an empty stack and an empty string for the postfix expression.
2. Scan the infix expression from left to right.
3. If the current token is an operand (a variable or constant), append it to the postfix expression.
4. If the current token is an operator, pop operators from the stack and append them to the postfix expression until the stack is empty or the top operator has lower precedence than the current operator. Then push the current operator onto the stack.
5. If the current token is an opening parenthesis, push it onto the stack.
6. If the current token is a closing parenthesis, pop operators from the stack and append them to the postfix expression until an opening parenthesis is encountered. Discard the opening and closing parentheses.
7. After scanning the infix expression, pop any remaining operators from the stack and append them to the postfix expression.
8. The resulting string is the postfix expression.

Using this algorithm, we can convert $$A-B/(C*D^E)$$ to postfix as follows:

1. Start with an empty stack and an empty string: stack = [], postfix = ""
2. Scan the infix expression from left to right:
   - A is an operand, so append it to the postfix expression: postfix = "A"
   - - is an operator, so push it onto the stack: stack = ["-"]
   - B is an operand, so append it to the postfix expression: postfix = "AB"
   - / is an operator with higher precedence than -, so push it onto the stack: stack = ["/", "-"]
   - ( is an opening parenthesis, so push it onto the stack: stack = ["(", "/", "-"]
   - C is an operand, so append it to the postfix expression: postfix = "ABC"
   - * is an operator with higher precedence than /, so push it onto the stack: stack = ["*", "(", "/", "-"]
   - D is an operand, so append it to the postfix expression: postfix = "ABCD"
   - ^ is an operator with higher precedence than *, so push it onto the stack: stack = ["^", "*", "(", "/", "-"]
   - E is an operand, so append it to the postfix expression: postfix = "ABCDE"
   - ) is a closing parenthesis, so pop operators from the stack and append them to the postfix expression until an opening parenthesis is encountered. Discard the parentheses: postfix = "ABCDE^*CDE/-"
3. Pop any remaining operators from the stack and append them to the postfix expression: postfix = "ABCDE^*CDE/-"
4. The resulting postfix expression is $$ABCDE^*CDE/-$$