forked from krishnamanojpvr/DSCPP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path48_Circular_Queue_Array.cpp
65 lines (65 loc) · 1018 Bytes
/
48_Circular_Queue_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
#include<iostream>
using namespace std;
#define N 5
int arr[N];
int front = -1;
int rear = -1;
void en(int x){
if((rear+1)%N == front){
cout<<"Overflow"<<endl;
}
else if(front==-1 && rear==-1){
front = rear = 0;
arr[rear] = x;
}
else{
rear = (rear+1)%N;
arr[rear] = x;
}
}
void de(){
if(front==-1 && rear==-1){
cout<<"Underflow"<<endl;
}
else if(front==rear){
front = rear = -1;
}
else{
front=(front+1)%N;
}
}
void display(){
if(front==-1 && rear==-1){
cout<<"Underflow"<<endl;
}
else{
int i = front;
while(i!=rear){
cout<<arr[i]<<",";
i = (i+1)%N;
}
cout<<arr[i]<<endl;
}
}
int main()
{
en(1);
en(2);
en(3);
en(4);
en(5);
display();
en(6);
de();
display();
de();
display();
en(6);
display();
en(7);
display();
en(8);
de();
display();
return 0;
}