forked from xuos/xiuos
APP_Framework/lib/:add queue lib
This commit is contained in:
59
APP_Framework/lib/queue/queue.c
Normal file
59
APP_Framework/lib/queue/queue.c
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <queue.h>
|
||||
Status InitQueue(SqQueue *Q)
|
||||
{
|
||||
Q->front=0;
|
||||
Q->rear=0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Status ClearQueue(SqQueue *Q)
|
||||
{
|
||||
Q->front=Q->rear=0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Status QueueEmpty(SqQueue *Q)
|
||||
{
|
||||
if(Q->front==Q->rear)
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
int QueueLength(SqQueue *Q)
|
||||
{
|
||||
return (Q->rear-Q->front+MAXSIZE)%MAXSIZE;
|
||||
}
|
||||
|
||||
|
||||
Status GetHead(SqQueue *Q,QElemType *e)
|
||||
{
|
||||
if(Q->front==Q->rear)
|
||||
return ERROR;
|
||||
*e=Q->data[Q->front];
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Status EnQueue(SqQueue *Q,QElemType e)
|
||||
{
|
||||
if ((Q->rear+1)%MAXSIZE == Q->front)
|
||||
return ERROR;
|
||||
Q->data[Q->rear]=e;
|
||||
Q->rear=(Q->rear+1)%MAXSIZE;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Status DeQueue(SqQueue *Q,QElemType *e)
|
||||
{
|
||||
if (Q->front == Q->rear)
|
||||
return ERROR;
|
||||
*e=Q->data[Q->front];
|
||||
Q->front=(Q->front+1)%MAXSIZE;
|
||||
return OK;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user