如何评估任何给定的表达式 [英] How to evaluate any given expression
问题描述
在给定任何字符串表达式的情况下,如何填充树?
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屋!