#include <iostream>
#include <string>
#include <stack>
#include <fstream>
using namespace std;
bool isone(char c){
return (c=='+' || c=='-');
}
bool istwo(char c){
return (c=='*' || c=='/');
}
string shorten(string m){
stack<char> s;
string sur;
int i;
char w;
sur;
for(i=0;i<m.size();i++){
if(isdigit(m[i]) || m[i]=='.'){
while(isdigit(m[i]) || m[i]=='.') sur += m[i++];
i--;
sur += '$';
}
else if(isone(m[i])){
while(s.size() && (isone(s.top()) || istwo(s.top()))){
sur+=s.top();
s.pop();
}
s.push(m[i]);
}
else if(m[i]==')'){
while(s.top()!='('){
sur+=s.top();
s.pop();
}
s.pop();
}
else if(istwo(m[i])){
while(s.size() && istwo(s.top())){
sur+
表达式求值 【栈的应用 或 二叉树的应用
最新推荐文章于 2023-06-15 22:13:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)