难以理解如何处理调车场算法的输出

编程入门 行业动态 更新时间:2024-10-16 22:18:58
本文介绍了难以理解如何处理调车场算法的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在查看Wiki页面: en.wikipedia/ wiki / Shunting-yard_algorithm

I've been looking at the wiki page: en.wikipedia/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.

这没关系,但我正在使用 C#。

Not that it matters but I am working 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

更多推荐

难以理解如何处理调车场算法的输出

本文发布于:2023-11-29 12:11:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646360.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:调车场   如何处理   算法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!