帮我看一下,有关队的输出,为什么输出问号呀?
循环队列#include<stdio.h>
#include<stdlib.h>
#define MAX 10
struct M
{
char*base;
int front;
int rear;
int len;
};
void init(struct M*sq) //建队
{
sq->base=(char*)malloc(MAX*sizeof(char));
sq->len=0;
sq->rear=0;
sq->front=0;
}
void rudui(struct M*sq,char x) //入队
{
if(sq->len==MAX)
{
printf("队满!\n");
exit(0);
}
else
{
x=sq->base[sq->rear];
sq->len++;
sq->rear=(sq->rear+1)%MAX;
}
}
void chudui(struct M*sq,char*e) //出队
{
if(sq->len==0)
{
printf("队空!\n");
exit(0);
}
*e=sq->base[sq->front];
sq->front=(sq->front+1)%MAX;
sq->len--;
}
void main()
{ char ch;
struct M S;
int y,z,h;
init(&S);
while((ch=getchar())!='\n')
rudui(&S,ch);
while(S.len!=0)
{
chudui(&S,&ch);
printf("%c\n",ch);
}
}
比如输入abc,为什么输出3个问号