#include <string.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
/*栈*/
template <class T>
class Stack{
public:
int MaxTop; //最大的栈顶值
T *stack; //堆栈元素数组
int top; //栈顶
Stack(int count){
stack=new T[count];
MaxTop=count;
top=-1; //栈为空
}
//添加新元素
bool Add(const T& x){
//添加元素x
if(top==MaxTop-1){
return false;
} else{
stack[++top]=x;
}
}
//判断是否为空栈
bool IsEmpty() const {return top==-1;}
//返回栈顶元素
T Top(){
if(IsEmpty()){
cout<<"空栈,无法返回栈顶元素!"<<endl;
return -1;
} else{
return stack[top--];
}
}
T GetElement(){
if(IsEmpty()){
return 0;
}
return stack[top];
}
~Stack(){
delete [] stack;
}
};
/**操作函数定义**/
bool ExpressionisRight(char * Expression);//表达式是否正确
bool ProcessExpression(char * Expression);//处理表达式
int GetIndex(char ch); //获取操作符在数组中的下标
void Calculate(); //计算
double GetResult(); //得到结果
bool IsEnd(char ch); //表达式是否结束
double GetNum(char *Str,int & l); //获取操作数
Stack<char> stack_sign(100); // 运算符栈
Stack<double> stack_num(100); // 操作数栈
//运算符号优先等级表