难以理解如何处理调车场算法的输出 [英] Trouble understanding what to do with output of shunting-yard algorithm
问题描述
我一直在查看Wiki页面: http://en.wikipedia.org/ wiki / Shunting-yard_algorithm
I've been looking at the wiki page: http://en.wikipedia.org/wiki/Shunting-yard_algorithm
我已经使用代码示例构建了第一部分,基本上我现在可以打开:
I've used the code example to build the first part, basically I can currently turn :
3 + 4 * 2 /(1-5)^ 2 ^ 3
到 3 4 2 * 1 5- 2 3 ^ ^ / +
但是我不知道该如何使用 3 4 2 * 1 5 − 2 3 ^ ^ / +
获得 3.00012207
But I don't know how to then use 3 4 2 * 1 5 − 2 3 ^ ^ / +
to obtain 3.00012207
以及示例代码和
有人可以解释如何评估 3 4 2 * 1 5 − 2 3 ^ ^ / +
并给出答案。提前致谢。我不需要代码示例,只是一个很好的解释或示例细分。
Could someone please explain how to evaluate 3 4 2 * 1 5 − 2 3 ^ ^ / +
and produce the answer. Thanks in advance. I don't need a code example just a good explanation or a breakdown of an example.
这没关系,但我正在使用.net C#。
Not that it matters but I am working .net C#.
推荐答案
调车场算法的目的是其输出位于反向波兰符号,它很容易评估:
The purpose of the shunting yard algorithm is that its output is in Reverse Polish Notation, which is straightforward to evaluate:
- 创建一个堆栈来保存值
- 同时还有反向抛光符号输入:
- 读取输入项
- 如果它是一个值,则将其压入堆栈
- 否则,它是一个操作;从堆栈中弹出值,对这些值执行操作,将结果推回
- create a stack to hold values
- while there is reverse polish notation input left:
- read an item of input
- if it is a value, push it onto the stack
- otherwise, it is an operation; pop values from the stack, perform the operation on those values, push the result back
这篇关于难以理解如何处理调车场算法的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!