Int op(int a,char Op,int b)
{
if(Op=='+')return a+b;
if(Op=='-')return a-b;
if(Op=='*')return a*b:;
if(Op=='/')
{
if(b==0)
{
cout<<"ERROR"<<endl;
return 0;
}
else
return a/b;
}
}
int com(char exp[])
{
int i,a,b,c:
int stack[maxsize]; int top--1;
char Op:
for(i=0;exp[i]!-'\0';++1)
{
if(exp[i]>='0'&&exp[i]<-'9')
stack[++top]=exp[i]-'0';
else
{
Op=exp[i];
b=stack[top--];
a=stack[top--];
c=op(a,Op,b);
stack[++top]=c;
}
}
return stack[top];
}
栈的应用3表达式求值
最新推荐文章于 2024-08-14 23:48:25 发布