循环队列,删除队头元素时出错
程序代码:
#include"stdio.h" #define QueueSize 50 /*这是用到的基本函数*/ typedef int ElemType; typedef struct { ElemType *elem; int front; int rear; }SeqQueue; void InitQueue(SeqQueue *Q) { Q->elem=(ElemType *)malloc(sizeof(ElemType)*QueueSize); if(Q->elem==NULL) exit(1); Q->front=Q->rear=0; } int Empty(SeqQueue Q) { if(Q.front==Q.rear) return 1; } int Full(SeqQueue Q) { if(Q.front==(Q.rear+1)%QueueSize) return 1; } void InsertElem(SeqQueue *Q,ElemType x) { if(Full(*Q)==1) printf("The Queue is FULL!\n"); else { Q->elem[Q->rear]=x; Q->rear=(Q->rear+1)%QueueSize; } } void DeElem(SeqQueue *Q,ElemType *x) { if(Empty(*Q)==1) printf("The Queue is EMPTY!\n"); else { *x=Q->elem[Q->front]; Q->front=(Q->front+1)%QueueSize; } } void Print(SeqQueue Q) { if(Empty(Q)==1) printf("The Queue is EMPTY!\n"); else { int i,t=0; for(i=Q.front;t<Length(Q);t++,i=(i+1)%QueueSize) printf("%d,",Q.elem[i]); } }