求指教谢谢,建立循环队列并输出,插入元素并输出队列
#include<stdio.h>#include<stdlib.h>
#define MAXSIZE 10
typedef struct
{
int elem[MAXSIZE];
int front;
int rear;
}Queue;
void inputqueue(Queue Q,int elem[]);
void outputqueue(Queue Q,int elem[]);
int insertqueue(Queue Q,int elem[],int x);
int main()
{
int x;
int elem[MAXSIZE];
Queue Q;
Q.front=Q.rear=0;
inputqueue(Q,elem);
outputqueue(Q,elem);
insertqueue(Q,elem,x);
return 0;
}
void inputqueue(Queue Q,int elem[])
{
int i=0;
printf("input queue element<eng of -99>:");
do
{
scanf("%d",&elem[i]);
if(elem[i]==-99)
break;
i++;
}while(i<MAXSIZE);
}
void outputqueue(Queue Q,int elem[])
{
int i;
printf("\n输出:");
for(i=0;i<MAXSIZE;i++)
{
if(elem[i]==-99)
break;
printf("%d ",elem[i]);
}
printf("\n");
}
int insertqueue(Queue Q,int elem[],int x)
{
int k;
int i;
if((Q.rear+1)%MAXSIZE==Q.front)
printf("\n队列满!");
else
{
printf("insert?1/0 ");
scanf("%d",&k);
if(k==1)
{
printf("\ninput insert element:");
scanf("%d",&x);
Q.elem[Q.rear]=x;
Q.rear=(Q.rear+1)%MAXSIZE;
printf("\ninsert successful!");
printf("\nqueue element are:");
for(i=0;i<MAXSIZE+1;i++)
{
if(elem[i]==-99)
break;
printf("%d ",elem[i]);
}
printf("\n");
}
}
return 1;
}
想要把X插入队列并输出可是输不进去输出的队列不包含X