📄 loop_queue.c
字号:
#include "loop_queue.h"
#include <stdio.h>
#include <stdlib.h>
PLOOP_QUEUE CreateLQueue()
{
PLOOP_QUEUE queue = (PLOOP_QUEUE)malloc(sizeof(LOOP_QUEUE));
if(NULL == queue)
{
printf("memory overflow!\n");
exit(1);
}
queue->front = queue->rear = 0;
return queue;
}
BOOL DestroyLQueue(PLOOP_QUEUE * queue)
{
if(NULL == *queue)
return FALSE;
else
{
free(*queue);
*queue = NULL;
return TRUE;
}
}
BOOL EnLQueue(PLOOP_QUEUE queue, QUEUE_ELEMENT_TYPE elem)
{
if((queue->rear + 1) % MAX_QUEUE_SIZE == queue->front)
return FALSE;
queue->data[queue->rear] = elem;
queue->rear = (queue->rear + 1) % MAX_QUEUE_SIZE;
return TRUE;
}
BOOL DeLQueue(PLOOP_QUEUE queue, QUEUE_ELEMENT_TYPE * elem)
{
if(queue->front == queue->rear)
return FALSE;
*elem = queue->data[queue->front];
queue->front = (queue->front + 1) % MAX_QUEUE_SIZE;
return TRUE;
}
BOOL LQueueEmpty(PLOOP_QUEUE queue)
{
if(queue->front == queue->rear)
return TRUE;
else
return FALSE;
}
BOOL LQueueFull(PLOOP_QUEUE queue)
{
if((queue->rear + 1) % MAX_QUEUE_SIZE == queue->front)
return TRUE;
else
return FALSE;
}
SIZE_T LQueueLength(PLOOP_QUEUE queue)
{
return (SIZE_T)((queue->rear - queue->front + MAX_QUEUE_SIZE) % MAX_QUEUE_SIZE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -