将中缀转换为后缀的伪代码
我正在努力获取伪代码。
从左到右扫描字符串中的每个字符 如果操作数将其添加到字符串 else if 运算符添加到堆栈 ....
我正在努力解决如何处理 ( ) 的问题
I'm struggling getting the pseudo code for this.
Scan string left to right for each char
If operand add it to string
Else if operator add to stack
....
i'm struggling on how to handle ( )s
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您尝试过这些链接吗?
http://www.geocities.com/e_i_search/premshree/web-include/pub/infix-postfix/index.htm
http://code.activestate.com/recipes/228915-infixpostfix/
Have you tried these links yet?
http://www.geocities.com/e_i_search/premshree/web-include/pub/infix-postfix/index.htm
http://code.activestate.com/recipes/228915-infixpostfix/
(
进入堆栈,然后当您到达)
时,您会从堆栈中弹出,直到找到(
。维基百科对该算法有更详细的描述,支持函数和运算符。
(
goes on to the stack, then when you get to)
you pop from the stack until you find a(
.Wikipedia has a more detailed description of the algorithm, supporting functions as well as operators.
进入操作员堆栈。
操作符堆栈,将该操作符压入操作数堆栈。
运算符堆栈的运算符,从操作数堆栈中弹出运算符,直到
我们发现一个比扫描字符优先级低的运算符。永远不会弹出
( '(' ) 或 ( ')' ) 无论扫描的优先级是什么
特点。
堆。
运算符堆栈,直到找到左括号 ('(' )。
进入输出堆栈。
into operators' stack.
of operator's stack, push this operator into operand's stack.
operator of operator's stack, pop the operators from operand's stack until
we find a low precedence operator than the scanned character. Never pop out
( '(' ) or ( ')' ) whatever may be the precedence level of scanned
character.
stack.
operator's stack until we find an opening bracket ('(' ).
into output stack.
我对此有点生疏,但是当你遇到 '(' 时,你会将它推入堆栈,因为它具有最高的优先级。我不记得遇到 ')' 时该怎么做,但我认为它会继续堆栈也是如此,因为它的优先级最高。
I am a bit rusty at this, but when you encounter a '(' , you push it onto the stack because it has the highest precedence. I cant remember what to do when you encounter ')', but i think it goes on the stack as well because its the highest precedence.