Problem description:
Prefix-to-infix example, with extra parentheses allowed:
* + 4 2 + 3 6 => (4 + 2) * (3 + 6)
-+/3 4 2 5 => (3/4 + 2)-5
-+ 3/4 2 5 => (3 + 4/2)-5
Thought 1 (recursion ):
1. Scan from left to right
2. If an operator is encountered, a recursive solution is used to return a new string. If a number is encountered, a numeric string is directly returned. For example:
Case '*':
Return "(" + exp () + "*" + exp () + ")"; // note that brackets are added to ensure that the infix expression can be correctly solved.
Default:
Return next_str;
Idea 2 (tree ):
1. Scan from left to right
2. Construct a subtree continuously based on operators
3. traverse the tree in the middle order and output it to obtain the infix expression.
Reprinted, please indicate the reference from:
Http://www.cnblogs.com/breakthings/p/4051912.html
Prefix to infix (expression)