1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include "queue.h" #define BUF_SIZE 100 static int queue_buf[BUF_SIZE]; static int head = 0, tail = 0; void enq(int val) { queue_buf[tail++ % BUF_SIZE] = val; } int deq() { if (head == BUF_SIZE) { head = 0; tail -= BUF_SIZE; } return queue_buf[head++]; } int can_enq() { return (tail < head + BUF_SIZE); } int can_deq() { return (head < tail); }