匿名用户
1级
2013-07-18 回答
#include
#include
#include
#include
#define MaxQSize 80
float qlist[MaxQSize],qlist1[MaxQSize],qlist2[MaxQSize]; //定义三个全局队列
int front=0,rear=0,front1=0,front2=0,rear1=0,rear2=0,count=0,count1=0,count2=0;//定义三个队列头结点、尾结点、数据个数
main()
{
char c[80];
void Enter(float),pop(),ClearStack();
printf("input string:(n:sin,o:cos,s:sqrt)\n");
while(gets(c),*c!='q' ||*c!='Q')
{
switch(*c)
{
case '+':
case '*':
case 's':
case 'n': //求SIN
case 'o': //求COS
case '/': //将符号入第一个队列
{
if(count==MaxQSize)
{
printf("Quere overflow!");
exit(1);
}
count++;
qlist[rear]=*c;
rear=(rear+1)%MaxQSize;
break;}
case '-':
{
if(strlen(c)>1) //如果是负号,则将负号和数一起入第二个队列
Enter(atof(c));
else //否则,说明是减号,入第一队列
if(count==MaxQSize)
{
printf("Quere overflow!");
exit(1);
}
...#include
#include
#include
#include
#define MaxQSize 80
float qlist[MaxQSize],qlist1[MaxQSize],qlist2[MaxQSize]; //定义三个全局队列
int front=0,rear=0,front1=0,front2=0,rear1=0,rear2=0,count=0,count1=0,count2=0;//定义三个队列头结点、尾结点、数据个数
main()
{
char c[80];
void Enter(float),pop(),ClearStack();
printf("input string:(n:sin,o:cos,s:sqrt)\n");
while(gets(c),*c!='q' ||*c!='Q')
{
switch(*c)
{
case '+':
case '*':
case 's':
case 'n': //求SIN
case 'o': //求COS
case '/': //将符号入第一个队列
{
if(count==MaxQSize)
{
printf("Quere overflow!");
exit(1);
}
count++;
qlist[rear]=*c;
rear=(rear+1)%MaxQSize;
break;}
case '-':
{
if(strlen(c)>1) //如果是负号,则将负号和数一起入第二个队列
Enter(atof(c));
else //否则,说明是减号,入第一队列
if(count==MaxQSize)
{
printf("Quere overflow!");
exit(1);
}
count++;
qlist[rear]=*c;
rear=(rear+1)%MaxQSize;
break;}
case '=':
pop(); //显示结果
break;
case 'c':
ClearStack();
break;
case 'q':
ClearStack();
exit(1);
default:
Enter(atof(c));
break;
}
}
return 0;
}
void Enter(float num) //将数据入第二个队列
{
if(count1==MaxQSize)
{
printf("Queue overflow!\n");
exit(1);
}
count1++;
qlist1[rear1]=num;
rear1=(rear1+1)%MaxQSize;
}
void ClearStack() //将三个队列清空
{
count=0;
count1=0;
)%MaxQSize;
QInsert(number);
}
break;
case '-':
if(count2==0)
{
num2=QFront1();
number=num1-num2;
printf("number=%f\n",number);
QInsert(number);
}
else
{
number=qlist2[front2]-num1;
printf("number=%f\n",number);
front2=(front2+1)%MaxQSize;
QInsert(number);
}
break;