表达式求值
#include
stack
int getIndex(char theta) //获取theta所对应的索引 {
int index = 0; switch (theta) { case '+': index = 0; break; case '-': index = 1;
break; case '*': index = 2; break; case '/': index = 3; break; case '(': index = 4; break; case ')': index = 5; break; case '#': index = 6; default:break; }
return index; }
char getPriority(char theta1, char theta2) //theta2之间的优先级
获取theta1与{
const char priority[][7] = //算符间的优先级关系 {
{ '>','>','<','<','<','>','>' }, { '>','>','<','<','<','>','>' }, { '>','>','>','>','<','>','>' }, { '>','>','>','>','<','>','>' }, { '<','<','<','<','<','=','0' }, { '>','>','>','>','0','>','>' }, { '<','<','<','<','<','0','=' }, };
int index1 = getIndex(theta1); int index2 = getIndex(theta2); return priority[index1][index2]; }
double calculate(double b, char theta, double a) //theta a {
switch (theta) {
计算b