伙计表达评估员 [英] guys expression evaluator

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

问题描述

任何人都可以给我一个评估字符串表达的想法..(3 + 2-(4 * 3/5)+2等等..它也检查运算符优先级......


i使用中缀,后缀符号完成此代码..但搜索更多的想法(最简单的方法..)..


???? :)

谢谢..

can any one give me idea to evaluate an string experssion.. (3+2-(4*3/5)+2 and so on.. it shld also check for the operator precedence...

i finished this code using infix,postfix notations.. but searching for any more ideas (simplest method..) ..

???? :)
thank you..

推荐答案

使用堆栈。然后,当你得到像(3 + 2)这样的东西时,你弹出所有这些字符并按下等效值,5。
Use a stack. Then, when you get to something like (3+2), you pop all of those characters and push the equivalent value, 5.


但我的教练告诉我有办法评估表达式没有使用任何额外的内存..但只有少数临时变量就足够了...

任何想法???
but my trainer told me that there is way to evaluate the expression without using any extra memory.. but only few temp variables are enough...
any idea???


在这种情况下,你可以选择两个数字在括号的相同级别上,并覆盖数字。一定要先乘以除。这是你提供的表达式的贯穿。
In that case, you can pick two numbers on the same level of parenthesis, and overwrite the numbers. Be sure to multiply and divide first. Here''s a run through on the expression you provided.
展开 | 选择 | Wrap | 行号


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

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