Browse Source

APP_Framework/lib:add comments in queue

pull/9/head
chunyexixiaoyu 1 year ago
parent
commit
88d7ef83d3
  1. 57
      APP_Framework/lib/queue/queue.c
  2. 10
      APP_Framework/lib/queue/queue.h

57
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 <queue.h>
/**
* @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)

10
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 <stdio.h>
@ -11,7 +19,7 @@ typedef int Status;
typedef int QElemType;
typedef struct
{
int data[MAXSIZE];
QElemType data[MAXSIZE];
int front;
int rear;
}SqQueue;

Loading…
Cancel
Save