link:http://www.cnblogs.com/kaituorensheng/archive/2013/02/28/2937865.html
typedef struct queue
{int queuesize; //数组的大小
int head, tail; //队列的头和尾下标
int *q; //数组头指针
}Queue;
{
q->queuesize = 8;
q->q = (int *)malloc(sizeof(int ) * q->queuesize); //分配内存
q->tail = 0;
q->head = 0;
}
{
int tail = (q->tail+1) % q->queuesize; //取余保证,当quil=queuesize-1时,再转回0
if (tail == q->head) //此时队列没有空间
{
printf("the queue has been filled full!");
}
else
{
q->q[q->tail] = key;
q->tail = tail;
}
}
int DeQueue(Queue *q)
{
int tmp=NULL;
if(q->tail == q->head) //判断队列不为空
{
printf("the queue is NULL\n");
}
else
{
tmp = q->q[q->head];
q->head = (q->head+1) % q->queuesize;
}
return tmp;
}
int IsQueueEmpty(Queue *q)
{
if(q->head == q->tail)
{
return 1;
}
else
{
return 0;
}
}