typedef int * Pint; typedef struct{ Pint *base; int front; int rear; int queuesize; }SqQueue; 1.初始化 void initqueue(SqQueue &Q,int max){ Q.base=new Pint[max]; Q.front=Q.rear=0; Q.queuesize=max; } 2进队列 int enqueue(SqQueue &Q,Pint e){ if((Q.rear+1)%Q.queuesize==Q.front){ printf("队满\n");return 0; } else { Q.base[Q.rear]=e; Q.rear=(Q.rear+1)%Q.queuesize; return 1; } } 3.出队列 int outqueue(SqQueue &Q,Pint &e){ if(Q.rear==Q.front){ printf("队空\n");return 0; } else { e=Q.base[Q.front]; Q.front=(Q.front+1)%Q.queuesize; return 1; } } 4.显示 void dispqueue(SqQueue Q){ int p=Q.front; while(Q.rear-p+Q.queuesize)%Q.queuesize>0){ printf("%d<-",*Q.base[p]); p=(p+1)% Q.queuesize; } printf("\n"); }