
The only operators used in the expressions are ‘+’, ‘-’, ‘*’, ‘/’.
Input: ‘n’ = 5, ‘s’ = “/A+BC”
Output: ABC+/
Explanation: For ‘s’ = “/A+BC”, the correct postfix expression is “ABC+/”.
The first line is an integer ‘n’, denoting the string ‘s’ size.
The second line contains a string ‘s’, denoting the prefix expression.
Return a string representing the postfix form of the expression.
You don't need to print anything. Just implement the given function.
We can convert a prefix expression into a postfix expression using a stack. First, we will reverse the string and iterate through it. When we encounter an operand, we will push it into the stack. When meeting an operator ‘op’, we will pop two operands from the stack, ‘s1’ and ‘s2’. We will then push into the stack expression ‘s1’+’s2’+’op’, where + means concatenation. Ultimately, we will have our final expression as the only element in the stack.
function preToPost(string s):
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Hills and Soldier
Next Greater Element II
Implement Queue Using Linked List
Candle Box Cost
Signal Disruption Measurement