//队列,队首删除,队尾插入, 先进先出 #include<stdio.h> #define MaxSize 100 typedef char ElemType; typedef struct { ElemType queue[MaxSize];int front,rear; }queue; //init a queue void initqueue(queue *Q) { Q->front=Q->rear=-1; } //Enter the queue void enter(queue *Q,ElemType x) { if(Q->rear==MaxSize){ printf("The queue is too long~\n");}else{ Q->rear++;//remove the rearQ->queue[Q->rear]=x;} } //Delete an element void del(queue *Q) { if(Q->front==Q->rear){ printf("Empty queue!\n");}elseQ->front++; } //Get the first element ElemType gethead(queue *Q) { if(Q->front==Q->rear){ printf("Empty queue!\n");}elsereturn(Q->queue[Q->front+1]); } //Empty or not void empty(queue *Q) { if(Q->front==Q->rear){ printf("Empty queue!\n");}else{ printf("Not wmpty.");} } //Display the queue void display(queue *Q) { int i;printf("The element in the queue:\n");for(i=Q->front+1;i<=Q->rear;i++){ printf("%5c",Q->queue[i]);}printf("\n"); } void main() { queue a;queue *q=&a;printf("Inital:\n");initqueue(q);printf("Empty?:\n");empty(q);printf("Enter some word:\n");enter(q,'q');enter(q,'w');enter(q,'d');enter(q,'a');display(q);printf("Delete one.:\n");del(q);display(q);printf("The first Elem:%c\n",gethead(q));printf("Hello!\n"); }