mirror of
https://github.com/CodePanda66/CSPostgraduate-408.git
synced 2023-05-21 21:49:33 +08:00
🚚 add func define
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user