如何评估任何给定的表达式 [英] How to evaluate any given expression

查看:143
本文介绍了如何评估任何给定的表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定任何字符串表达式的情况下,如何填充树?

How do you, given any string expression, populate a tree?

我有一个任务,我被困在。

I have an assignment that I am stuck on.

我需要评估以下表达式((5 * 10)/ 2 - ((2 + 3)+ 6))使用任何数据结构。

I need to evaluate the following expression (( 5 * 10 ) /2 - (( 2 + 3) + 6)) using any data structure.

使用堆栈,我可以验证字符串是否正确。但是如何将各种值添加到树中,然后按顺序进行评估。

Using a stack, I am able to verify that the string is well formed. But how can I add the various values into a tree and then evaluate them in order.

请给我任何关于我如何读取字符串(((490 * 9)/ 2)/ 5/6 - ((2/4 + 3)+ 6 * 5))

Please give me any hints you may have on how I can read the string ((( 490 * 9 ) / 2)/5/6 - (( 2/4 + 3) + 6 * 5))

例如, c> - )成为三个的根,当它是输入表达式中的第15个子字符串?我如何确保( / )6表达式发生在 /

For instance, How do I get the (-) to be the root of the three when it is the 15th substring in the input expression? How do I make sure that the (/)6 expression happens after (/)5 etc.

推荐答案

您正在寻找的是这里提供: http://www.codeproject.com/Articles/88435/Simple-Guide-to-Mathematical-Expression-Parsing

What you are looking for is provided here: http://www.codeproject.com/Articles/88435/Simple-Guide-to-Mathematical-Expression-Parsing

这篇关于如何评估任何给定的表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆