请把以下代码补充完整:顺序实现表达式求值#includeiostream#includestdlibh#includestdiohusing namespace std;顺序栈定义#define OK 1#define ERROR 0#define OVERFLOW -2#define MAXSIZE 100typedef int Status;typedef int SElemType;typ
// In函数补充 Status In(SElemType c) { if(c >= '0' && c <= '9') return true; else return false; }
// Precede函数补充 SElemType Precede(SElemType t1,SElemType t2) { SElemType f; switch(t2) { case '+': case '-': if(t1 == '(' || t1 == '#') f = '<'; else f = '>'; break; case '': case '/': if(t1 == '' || t1 == '/' || t1 == ')') f = '>'; else f = '<'; break; case '(': if(t1 == ')') { cout<<"括号不匹配"<<endl; exit(ERROR); } else f = '<'; break; case ')': switch(t1) { case '(': f = '='; break; case '#': cout<<"括号不匹配"<<endl; exit(ERROR); default: f = '>'; break; } break; case '#': if(t1 == '#') f = '='; else if(t1 == '(') { cout<<"括号不匹配"<<endl; exit(ERROR); } else f = '>'; break; } return f; }
// Operate函数补充 SElemType Operate(SElemType a,SElemType theta,SElemType b) { SElemType c; int x = a - '0'; int y = b - '0'; switch(theta) { case '+': c = x + y + '0'; break; case '-': c = x - y + '0'; break; case '*': c = x * y + '0'; break; case '/': c = x / y + '0'; break; } return c;
原文地址: https://www.cveoy.top/t/topic/dxlV 著作权归作者所有。请勿转载和采集!