diff --git a/APP_Framework/lib/queue/queue.c b/APP_Framework/lib/queue/queue.c index 03949890..750b0943 100644 --- a/APP_Framework/lib/queue/queue.c +++ b/APP_Framework/lib/queue/queue.c @@ -1,4 +1,19 @@ +/* + * @Author: chunyexixiaoyu + * @Date: 2021-08-16 15:16:51 + * @LastEditTime: 2021-08-18 14:45:47 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: \xiuos\APP_Framework\lib\queue\queue.c + */ #include + + +/** + * @description: Initialize an empty queue + * @param {SqQueue} *Q queue struct + * @return {*} + */ Status InitQueue(SqQueue *Q) { Q->front=0; @@ -6,14 +21,23 @@ Status InitQueue(SqQueue *Q) return OK; } - +/** + * @description: Clear Q to an empty queue + * @param {SqQueue} *Q queue struct + * @return {*} + */ Status ClearQueue(SqQueue *Q) { Q->front=Q->rear=0; return OK; } - +/** + * @description: Return TRUE if Q is an empty queue, FALSE otherwise + * @param {SqQueue} *Q queue struct + * @return TRUE + * FALSE + */ Status QueueEmpty(SqQueue *Q) { if(Q->front==Q->rear) @@ -22,13 +46,23 @@ Status QueueEmpty(SqQueue *Q) return FALSE; } - +/** + * @description: Returns the number of elements of Q, which is the current length of the queue + * @param {SqQueue} *Q queue struct + * @return length of the queue + */ int QueueLength(SqQueue *Q) { return (Q->rear-Q->front+MAXSIZE)%MAXSIZE; } - +/** + * @description: If the queue is not empty, return the header element of Q with e and OK, otherwise return ERROR + * @param {SqQueue} *Q queue struct + * @param {QElemType} *e header element + * @return TRUE + * FALSE + */ Status GetHead(SqQueue *Q,QElemType *e) { if(Q->front==Q->rear) @@ -37,7 +71,13 @@ Status GetHead(SqQueue *Q,QElemType *e) return OK; } - +/** + * @description: If the queue is not full, insert element E as Q's new tail element + * @param {SqQueue} *Q queue struct + * @param {QElemType} e new element + * @return TRUE insert successfully + * FALSE + */ Status EnQueue(SqQueue *Q,QElemType e) { if ((Q->rear+1)%MAXSIZE == Q->front) @@ -47,7 +87,12 @@ Status EnQueue(SqQueue *Q,QElemType e) return OK; } - +/** + * @description: If the queue is not empty, the header element in Q is removed and its value is returned with e + * @param {SqQueue} *Q + * @param {QElemType} *e the header element + * @return {*} + */ Status DeQueue(SqQueue *Q,QElemType *e) { if (Q->front == Q->rear) diff --git a/APP_Framework/lib/queue/queue.h b/APP_Framework/lib/queue/queue.h index 56541cc9..8c06dd8a 100644 --- a/APP_Framework/lib/queue/queue.h +++ b/APP_Framework/lib/queue/queue.h @@ -1,3 +1,11 @@ +/* + * @Author: chunyexixiaoyu + * @Date: 2021-08-16 15:16:51 + * @LastEditTime: 2021-08-18 14:48:11 + * @LastEditors: Please set LastEditors + * @Description: In User Settings Edit + * @FilePath: \xiuos\APP_Framework\lib\queue\queue.h + */ #ifndef __QUEUE_H__ #define __QUEUE_H__ #include @@ -11,7 +19,7 @@ typedef int Status; typedef int QElemType; typedef struct { - int data[MAXSIZE]; + QElemType data[MAXSIZE]; int front; int rear; }SqQueue;