-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsqueue.cpp
More file actions
50 lines (44 loc) · 843 Bytes
/
squeue.cpp
File metadata and controls
50 lines (44 loc) · 843 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
#include "SQUEUE.h"
#include "STRUCT.h"
#include <iostream>
int IniSqueue(SqQueue& s){
s.base =new int[MQUEUESIZE];
s.front=s.rear=0;
return 1;
}
int isEmpty(SqQueue q){
return q.front==q.rear;
}
int isFull(SqQueue q){
if(q.front==(q.rear+1+ MQUEUESIZE)% MQUEUESIZE){
return OK;
}else{
return ERROR;
}
}
int EnQueue(SqQueue& Q,int num){
if(isFull(Q)){
return ERROR;
}else{
Q.base[Q.rear]=num;
Q.rear=(Q.rear+1)% MQUEUESIZE;
return OK;
}
}
int DeQueue(SqQueue& Q,int &num){
if(isEmpty(Q)){
return ERROR;
}else{
num=Q.base[Q.front];
Q.front=(Q.front+1)% MQUEUESIZE;
return OK;
}
}
Status ReleaseQueue(SqQueue& Q)
{
if (!Q.base)
return OK;
delete[] Q.base;
Q.base = NULL;
return OK;
}