摘要:表达式求值#include<iostream>//输入的表达式要以'#'结尾,如‘5+6*3/(3-1)#’#include<cstring>#include<cstdio>#include<cctype>#include<stack>usingnamespacestd;stack<char>opter;//运算符栈stack<double>opval;//操作数栈intgetIndex(chartheta){intindex=0;switch(theta){case'+':index=0;break;case'-':index=1;break;//获取theta所对应的索引case'*':index=2;break;case'/':index=3;break;case'(':index=4;break;case')':index=5;break;case'#':index=6;default:break;}returnindex;}chargetPriority(chartheta1,chartheta2)与theta2之间的优先级{//获取theta1constcharpriority[][7]=//算符间的优先级关系{{'>','>','<','<','<','>','>'},{'>','>','<','<','<','>','>'},{'>','>','>','>','<','>','>'},{'>','>','>','>','<','>','>'},{'<','<','<','<','<','=','0'},{'>','>','>','>'
温馨提示:当前文档最多只能预览
5 页,若文档总页数超出了
5 页,请下载原文档以浏览全部内容。