-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSqQueue.cpp
More file actions
54 lines (47 loc) · 771 Bytes
/
SqQueue.cpp
File metadata and controls
54 lines (47 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
// Created by yoran on 2022/3/24.
//
#include "SqQueue.h"
#include<iostream>
//初始化队列
void InitQueue(SqQueue& Q)
{
Q.front = Q.rear = 0;
}
//判断队空
bool QueueEmpty(SqQueue Q)
{
if (Q.front == Q.rear)
{
return true;
}
return false;
}
//入队
bool EnQueue(SqQueue& Q,ElemType e)
{
//队满
if ((Q.rear+1)%MaxSize == Q.front)
{
return false;
}
//入队
Q.data[Q.rear] = e;
//更新队尾
Q.rear = (Q.rear + 1) % MaxSize;
return true;
}
//出队
bool DeQueue(SqQueue& Q, ElemType& e)
{
//队空
if (QueueEmpty(Q))
{
return false;
}
//队首元素
e = Q.data[Q.front];
//更新队头
Q.front = (Q.front + 1) % MaxSize;
return true;
}