.
}
.
else
cout << \被余数不能为零!\
break;
case '^': value = pow(left,right); /*value = 1; }
return value;
if(right >= 0)
while(right--)
value *= left;
else { }*/
right = -right; while(right--)
value /= left;
.
void Computer(char *mid_equotion, Type len) {
.
Type right, left , result;
char *p_mid_equotion = mid_equotion; char after_equotion = ' ';
map
Oper['*'] = 4;
Oper['+'] = 3; Oper['/'] = 4;
Oper['^'] = 5; Oper[')'] = 6;
Stack MyStack; InitStack(&MyStack); Push_Char(&MyStack,'#');
char top_oper, current_oper; for(;*p_mid_equotion != '\\0';)
.
.
{
top_oper = Top_Char(MyStack); current_oper = *p_mid_equotion;
if(!Oper[current_oper]) {
Push_Type(&MyStack,strtod(p_mid_equotion, &p_mid_equotion)); continue;
}//end if else //为操作符 {
if(Oper[current_oper] > Oper[top_oper]) {
if(current_oper != ')')
Push_Char(&MyStack,current_oper);
else {
while(top_oper != '(')
.
{ right = Pop_Type(&MyStack); if(!IsEmpty_Type(MyStack))
left = Pop_Type(&MyStack);
else
left = 0;
Push_Type(&MyStack,Calculate(left,
Top_Char(MyStack))); Pop_Char(&MyStack);
top_oper = Top_Char(MyStack);
}
Pop_Char(&MyStack);
}//end else
}//end if else { if(current_oper == '(')
{
.
right,
.
.
}
Push_Char(&MyStack,current_oper); if(*(p_mid_equotion + 1) == '-')
Push_Type(&MyStack,0);
else { }
right = Pop_Type(&MyStack); if(!IsEmpty_Type(MyStack))
left = Pop_Type(&MyStack);
else
left = 0;
Push_Type(&MyStack,Calculate(left, right, top_oper)); Pop_Char(&MyStack); continue;
}//end else
}//end else p_mid_equotion++;