🚚 add func define

This commit is contained in:
Kim Yang
2020-08-16 14:15:35 +08:00
parent f7b45ed07c
commit f8d4e36746
9 changed files with 93 additions and 51 deletions

View File

@@ -15,16 +15,21 @@ typedef struct {
int front, rear;//对头指针和队尾指针
int size;//利用size变量记录队列长度并用作判满的条件有了size就不会浪费一个存储空间
} SqQueue;
//函数声明
void InitQueue(SqQueue &Q);//初始化
bool QueueEmpty(SqQueue Q);//判空
bool EnQueue(SqQueue &Q, int t);//入队操作
bool DeQueue(SqQueue &Q, int &x);//出队操作
bool GetHead(SqQueue Q, int &x);//获取队头元素,用x返回
/**定义模块**/
/**实现模块**/
//初始化
void InitQueue(SqQueue &Q) {
Q.rear = Q.front = 0;//初始化时队头队尾都指向0
Q.size = 0;//初试长度
}
//判空
bool QueueEmpty(SqQueue Q) {
if (Q.size == 0)//有了size条件不一样了
return true;
@@ -32,7 +37,6 @@ bool QueueEmpty(SqQueue Q) {
return true;
}
//入队操作
bool EnQueue(SqQueue &Q, int t) {
if (Q.size == MaxSize)return false;//队满,注意这里的判满条件
Q.data[Q.rear] = t;
@@ -41,7 +45,6 @@ bool EnQueue(SqQueue &Q, int t) {
return true;
}
//出队操作
bool DeQueue(SqQueue &Q, int &x) {
if (Q.size == 0)return false;//队空
x = Q.data[Q.front];
@@ -50,7 +53,6 @@ bool DeQueue(SqQueue &Q, int &x) {
return true;
}
//获取队头元素,用x返回
bool GetHead(SqQueue Q, int &x) {
if (Q.size == 0)return false;
x = Q.data[Q.front];