-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue implementation - static circular array.cpp
84 lines (74 loc) · 1.67 KB
/
queue implementation - static circular array.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
using namespace std;
const int MAX_LENGTH = 100;
class arrayQueueType{
int Rear; //addition
int Front; //deletion
int Length; //count
int arr[MAX_LENGTH];
public:
//constructor
arrayQueueType(){
Front = 0;
Rear = MAX_LENGTH - 1;
Length = 0;
}
//functions
int isEmpty(){
return Length == 0;
}
bool isFull(){
return Length == MAX_LENGTH;
}
void addQue(int Element){
if(isFull()){
cout << "Queue full!" << endl;
}
else{
Rear = (Rear + 1) % MAX_LENGTH;
arr[Rear] = Element;
Length++;
}
}
void deleteQueue(){
if(isEmpty()){
cout << "empty queue!" << endl;
}
else{
Front = (Front + 1) % MAX_LENGTH;
--Length;
}
}
int frontQueue(){ //get frony
//it takes boolean input and if true, it will continue the code, and if false it breaks and points to the like of the false statement
assert(!isEmpty());
return arr[Front];
} //or
/*void getFront(int &getFront){
getFront = arr[Front];
}*/
int RearQueue()
{
assert(!isEmpty());
return arr[Rear];
}
void printQueue()
{
assert(!isEmpty());
for(size_t i = Front; i != Rear + 1; i = (i + 1) % MAX_LENGTH){
cout << arr[i] << " ";
}
//cout << arr[Rear];
}
};
int main(){
arrayQueueType q1;
q1.addQue(10);
q1.addQue(20);
q1.addQue(30);
q1.addQue(40);
q1.deleteQueue();
cout << q1.RearQueue();
//q1.printQueue();
return 0;
}