#include "stdafx.h"#include#include struct CircleQueue{ int head; int tail; int length; int isFull; int *array;};CircleQueue* CreatCircleQueue(int length){ CircleQueue *q = (CircleQueue*)malloc(sizeof(struct CircleQueue)); q->length = length; q->tail = 0; q->head = 0; q->array = (int *)malloc(sizeof(int)*length); q->isFull = 0; return q;}int EnterQueue(CircleQueue* q,int x){ if(q->isFull == -1){ printf("\nError: The Circle Queue is full!\n"); return -1; }else{ q->head = q->head + 1; if(q->head > q->length - 1) q->head = 0; if(q->head == q->tail) q->isFull = -1; q->array[q->head] = x; } return 0;} int DelQueue(CircleQueue * q){ if(q->isFull == 0 && q->head == q->tail){ printf("Error: The Circle Queue is Empty!\n"); return -1; }else{ q->tail = q->tail + 1; if(q->tail > q->length-1) q->tail = 0; if(q->tail == q->head) q->isFull = 0; return 0; }}int ShowQueue(CircleQueue* q){ int i,j; int flag = 1; if(q->isFull == 0 && q->head == q->tail){ //printf("Queue is Empty!\n"); }else{ i = q->head; while(1){ printf(" %d ",q->array[i--]); if(i<0) i=9; if(i == q->tail) break; } printf("\n"); } return 0;} int main(){ CircleQueue *q = CreatCircleQueue(10); int i,j; for(j=1;j<=3;j++){ for(i=1;i<=5;i++){ EnterQueue(q,i*j); ShowQueue(q); } for(i=1;i<=5;i++){ DelQueue(q); ShowQueue(q); } } getchar(); return 0;}