-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeqQueue.c
More file actions
60 lines (51 loc) · 910 Bytes
/
SeqQueue.c
File metadata and controls
60 lines (51 loc) · 910 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
53
54
55
56
57
58
59
60
//
// Created by ys on 2019/4/12.
//
#include "SeqQueue.h"
#include "../tools.h"
//初始化队列
void Init(SeqQueue *Q)
{
Q->front = Q->rear = 0;
}
//入队操作
void EnQueue(SeqQueue *Q, ElemType e)
{
if((Q->rear+1)%MAXSIZE == Q->front)
{
printf("队列已满,无法进行入队操作\n");
exit(0);
} else
{
Q->rear = (Q->rear+1)%MAXSIZE;
Q->data[Q->rear] = e;
}
}
//出队操作
ElemType DeQueue(SeqQueue *Q)
{
if(Q->rear == Q->front)
{
printf("队列已空,无法进行出队操作\n");
exit(0);
} else
{
Q->front = (Q->front+1)%MAXSIZE;
return (Q->data[Q->front]);
}
}
//测试
void testQueue()
{
SeqQueue Q;
Init(&Q);
EnQueue(&Q, 1);
EnQueue(&Q, 2);
EnQueue(&Q, 3);
EnQueue(&Q, 4);
ElemType x = DeQueue(&Q);
x = DeQueue(&Q);
x = DeQueue(&Q);
x = DeQueue(&Q);
x = DeQueue(&Q);
}