队满:(rear+1)%N==front
#include<stdio.h> #define Elemtype int #define N 100 struct Queue { Elemtype data[N]; int front,rear; }; void initQueue(Queue &Q) { Q.rear=Q.front=0; } int enQueue(Queue &Q,Elemtype x) { if((Q.rear+1)%N==Q.front)return 0; Q.rear=(Q.rear+1)%N; Q.data[Q.rear]=x; return 1; } int deQueue(Queue &Q,Elemtype &x) { if(Q.rear==Q.front)return 0; Q.front=(Q.front+1)%N; x=Q.data[Q.front]; return 1; } int main() { Queue Q; initQueue(Q); enQueue(Q,12); enQueue(Q,2); Elemtype x; deQueue(Q,x); printf("%d",x); return 0; }
原文:http://blog.csdn.net/u010839382/article/details/39973643