经过一些谷歌搜索,我找到了它!
前缀到中缀
该算法是一种非尾递归方法。反转的输入字符串被完全压入堆栈。
prefixToInfix(stack)
1) IF stack is not empty
a. Temp -->pop the stack
b. IF temp is a operator
i. Write a opening parenthesis to output
ii. prefixToInfix(stack)
iii. Write temp to output
iv. prefixToInfix(stack)
v. Write a closing parenthesis to output
c. ELSE IF temp is a space -->prefixToInfix(stack)
d. ELSE
i. Write temp to output
ii. IF stack.top NOT EQUAL to space -->prefixToInfix(stack)
当堆栈顶部是
F(ABC)
然后我们进入算法,“A”被写入输出,因为它是当前的值
温度=A(比方说)
现在我如何根据算法在输出列上获得“ - ”,下一个临时值将是“B”,它是在最后一次递归调用之后从堆栈中弹出的。图表如何显示输出“((A-” ...
我在哪里做不正确的假设?有人可以麻烦解释一下吗?