#include#include #define QUEUESIZE 128 struct queue { unsigned char buff[QUEUESIZE]; int front; int tail; }; void QueueInit(struct queue *queue_t) { memset(queue_t,0,QUEUESIZE); queue_t->front=0; queue_t->tail=0; } int QueueIsEmpty(struct queue * queue_t ) { return queue_t->tail==queue_t->front; } int QueueisFull(struct queue * queue_t) { return queue_t->tail >= QUEUESIZE; } int QueueInsert(struct queue *queue_t , unsigned char word) { if(!QueueisFull(queue_t)){ queue_t->buff[queue_t->tail] = word; queue_t->tail++; }else { printf("Queue is Full n"); return -1; } } int QueueGetData(struct queue * queue_t ) { if(!QueueIsEmpty(queue_t)) { return queue_t->buff[queue_t->front++]; }else{ printf("Queue is Empty !n"); return -1; } } int QueueGetCount(struct queue * queue_t ) { return queue_t->tail - queue_t -> front ; } int main(int argc ,char ** argv ) { int index=0; struct queue queue_p; QueueInit(&queue_p); QueueInsert(&queue_p,22); QueueInsert(&queue_p,23); QueueInsert(&queue_p,24); QueueInsert(&queue_p,25); printf("count == %d n",index=QueueGetCount(&queue_p )); while(index--) printf("data = %d n",QueueGetData(&queue_p)); printf("count == %d n",index=QueueGetCount(&queue_p )); return 0; }



