标签:
#include <stdio.h> #include "queue.h" int main(void) { char *s = "abcd"; while (*s != ‘\0‘) enqueue(*s++); while (!is_empty()) putchar(dequeue()); putchar(‘\n‘); return 0; }
static int f = 0,r = 0, sz = 512; //f入队游标, r出队游标, sz队大小 static int queue[512]; //队存储空间 void enqueue(int item) //环形队列,当数组游标到达sz后,游标变为0 { f %= sz; queue[f++] = item; } int dequeue(void) { r %= sz; return queue[r++]; } int is_empty(void) { return f == r; } int is_full(void) { return (f+1)%sz == r; }
extern void enqueue(int item); extern int dequeue(void); extern int is_empty(void); extern int is_full(void);
标签:
原文地址:http://www.cnblogs.com/zhuyaguang/p/4840850.html