char Calval_InvertPoland(char Buffer[]){
InitStack(S);
int i = 0; ElemType c, e1, e2; //定义操作符,运算数值
while(Buffer[i]!="#"){ //对数组中逆波兰表达式元素计算
//如果当前元素是数字则入栈
if((Buffer[i]!="+")||(Buffer[i]!="-")||(Buffer[i]!="*")||(Buffer[i]!="/")){
Push(S,Buffer[i]);
}else{
//遇到操作符则取出栈顶的两个元素进行该操作符的运算,处理结果入栈进行下一轮的计算
if(!IsEmpty(S)){
Pop(S,e1);
Pop(S,e2);
c = Cal(e1,e2,Buffer[i]);
Push(S,c);
}
}
i++;
}
}
ElemType Cal(ElemType e1, ElemType e2, char opt){
ElemType x;
switch(opt){
case '+':
x = e1+e2;
break;
case '-':
x = e1-e2;
break;
case '*':
x = e1*e2;
break;
case '/':
x = e1/e2;
break;
default:
break;
}
return x;
}