APP_Framework/lib:add comments in queue
This commit is contained in:
parent
09d86f55b0
commit
88d7ef83d3
|
@ -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>
|
#include <queue.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Initialize an empty queue
|
||||||
|
* @param {SqQueue} *Q queue struct
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
Status InitQueue(SqQueue *Q)
|
Status InitQueue(SqQueue *Q)
|
||||||
{
|
{
|
||||||
Q->front=0;
|
Q->front=0;
|
||||||
|
@ -6,14 +21,23 @@ Status InitQueue(SqQueue *Q)
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: Clear Q to an empty queue
|
||||||
|
* @param {SqQueue} *Q queue struct
|
||||||
|
* @return {*}
|
||||||
|
*/
|
||||||
Status ClearQueue(SqQueue *Q)
|
Status ClearQueue(SqQueue *Q)
|
||||||
{
|
{
|
||||||
Q->front=Q->rear=0;
|
Q->front=Q->rear=0;
|
||||||
return OK;
|
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)
|
Status QueueEmpty(SqQueue *Q)
|
||||||
{
|
{
|
||||||
if(Q->front==Q->rear)
|
if(Q->front==Q->rear)
|
||||||
|
@ -22,13 +46,23 @@ Status QueueEmpty(SqQueue *Q)
|
||||||
return FALSE;
|
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)
|
int QueueLength(SqQueue *Q)
|
||||||
{
|
{
|
||||||
return (Q->rear-Q->front+MAXSIZE)%MAXSIZE;
|
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)
|
Status GetHead(SqQueue *Q,QElemType *e)
|
||||||
{
|
{
|
||||||
if(Q->front==Q->rear)
|
if(Q->front==Q->rear)
|
||||||
|
@ -37,7 +71,13 @@ Status GetHead(SqQueue *Q,QElemType *e)
|
||||||
return OK;
|
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)
|
Status EnQueue(SqQueue *Q,QElemType e)
|
||||||
{
|
{
|
||||||
if ((Q->rear+1)%MAXSIZE == Q->front)
|
if ((Q->rear+1)%MAXSIZE == Q->front)
|
||||||
|
@ -47,7 +87,12 @@ Status EnQueue(SqQueue *Q,QElemType e)
|
||||||
return OK;
|
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)
|
Status DeQueue(SqQueue *Q,QElemType *e)
|
||||||
{
|
{
|
||||||
if (Q->front == Q->rear)
|
if (Q->front == Q->rear)
|
||||||
|
|
|
@ -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__
|
#ifndef __QUEUE_H__
|
||||||
#define __QUEUE_H__
|
#define __QUEUE_H__
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -11,7 +19,7 @@ typedef int Status;
|
||||||
typedef int QElemType;
|
typedef int QElemType;
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int data[MAXSIZE];
|
QElemType data[MAXSIZE];
|
||||||
int front;
|
int front;
|
||||||
int rear;
|
int rear;
|
||||||
}SqQueue;
|
}SqQueue;
|
||||||
|
|
Loading…
Reference in New Issue