CycleQueue--循环队列(c语言简单实现)

 1 #include<stdlib.h>
 2 
 3 #define SIZE 10
 4 typedef char ele;
 5 
 6 typedef struct{
 7     ele *e;
 8     int front;
 9     int rear;
10 }cycleQueue;
11 
12 
13 //initQueue
14 void initQueue(cycleQueue *q){
15     q = (cycleQueue *)malloc(sizeof(cycleQueue));
16     q->e = (ele *)malloc(SIZE*sizeof(ele));
17     q->front=q->rear=0;
18 }
19 
20 //insertQueue
21 void insertQueue(cycleQueue *q,ele e){
22     if(q->front==(q->rear+1)%SIZE)return;
23     q->e[q->rear]=e;
24     q->rear=(q->rear+1)%SIZE;
25 }
26 
27 //popQueue
28 ele popQueue(cycleQueue *q){
29     if(q->front==q->rear)return NULL;
30     ele e = q->e[q->front];
31     q->front=(q->front+1)%SIZE;
32     return e;
33 }

 

posted @ 2015-05-08 09:07  Object_mo  阅读(438)  评论(0编辑  收藏  举报
mozhuhao