简单的数值表达式求解器 [英] Simple numerical expression solver

查看:148
本文介绍了简单的数值表达式求解器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对不起我的英语。



对于我的最后一个项目我的算法和数据结构类,我需要创建一个简单的数值表达式求解器C ++。它需要解决简单的表达式,例如 3 * 12 +(4-6)。我设法分裂表达式,并从数字中分离运算符,但我不能再去任何进一步。窍门是把操作符放在二叉树上,但我没有设法做到这一点。



程序只需要使用默认的C ++ libs。



提前感谢。

解决方案



您需要将表达式转换为 reverse polish notation



[Reverse polish notation] [2]


First of all, sorry for my bad English.

For my last project on my Algorithms and Data Structures class, I need to create a simple numerical expression solver in C++. It needs to solve simple expressions like 3*12+(4-6). I managed to split the expression and separate the operators from the numbers, but I can't go any further. The trick is putting the operators on a binary tree, but I haven't managed to do that.

The program needs to use only the default C++ libs. Maybe there is some basic implementation I can build on?

Thanks in advance.

解决方案

Forget binary trees for a moment.

You need to convert the expression into reverse polish notation. During that conversion you are constructing a binary tree!

[Reverse polish notation][2]

这篇关于简单的数值表达式求解器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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