带变量的调车场算法

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

我目前正在开发Shunting Yard Algorithm的修改版本,该版本可以使用变量,但是我不知道如何使它起作用.例如,我希望算法重新编写2 *(2x + 5)-5到4x +5.是否有任何想法/指向已经实现的算法的链接?

I'm currently working on a modified version of the Shunting Yard Algorithm that would work with variables, but I cant figure out how to get it to work. For example, I would want the algorithm to re-write 2 * (2x + 5) - 5 to 4x + 5. Any ideas / links to already implemented algorithms that does this already?

推荐答案

  • 采用表达式: 2 *(2x + 5)-5
  • 添加*符号,使计算机更易理解: 2 *(2 * x + 5)-5
  • 使用Shunting Yard算法对其进行解析,结果变为: 2 2 x * 5 + * 5-(每个字符都可以看作是数组的元素).
  • 使用已解析的表达式,创建二叉树:
  • Take the expression: 2 * (2x + 5) - 5
  • Add the * symbol to make it more understandable for the computer: 2 * (2*x + 5) - 5
  • Parse it using the Shunting Yard Algorithm, it becomes: 2 2 x * 5 + * 5 - (Each character could be seen as an element of an array).
  • With the parsed expression, create the binary tree:
  • --/\* 5/\2 +/\* 5/\2倍5.定义代数规则并将其应用于树.例如,一条规则能够将 2 节点与 2 * x + 5 子树相乘".

    - / \ * 5 / \ 2 + / \ * 5 / \ 2 x 5. Define and apply algebraic rules to the tree. For example, a rule to be able to 'multiply' the 2 node with the 2 * x + 5 subtree.

    更多推荐

    带变量的调车场算法

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

    发布评论

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

    >www.elefans.com

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