-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQueue.c
More file actions
45 lines (38 loc) · 858 Bytes
/
Copy pathQueue.c
File metadata and controls
45 lines (38 loc) · 858 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
//
// Created by hanoi_ahoj on 2018/12/28.
//
#include "Queue.h"
Status InitQueue(SqQueue *q){
q->front = 0;
q->rear = 0;
return OK;
}
int QueueLength(const SqQueue *q){
return (q->rear-q->front+MAXSIZE) % MAXSIZE;
}
Status EnQueue(SqQueue *q, const QElemType e){
if (IsFull(q) == FULL){
return ERROR;
}
else{
q->data[q->rear] = e;
q->rear = (q->rear + 1) % MAXSIZE;
return OK;
}
}
Status DeQueue(SqQueue *q, QElemType *e){
if (IsEmpty(q) == EMPTY){
return ERROR;
}
else{
*e = q->data[q->front];
q->front = (q->front + 1) % MAXSIZE;
return OK;
}
}
Status IsFull (const SqQueue *q) {
return ((q->rear + 1) % MAXSIZE) == q->front ? FULL : NOTFULL;
}
Status IsEmpty(const SqQueue *q){
return q->front == q->rear ? EMPTY : NOTEMPTY;
}