-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion and deletion in Circular Q.cpp
More file actions
85 lines (85 loc) · 1.23 KB
/
insertion and deletion in Circular Q.cpp
File metadata and controls
85 lines (85 loc) · 1.23 KB
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
85
#include<iostream>
using namespace std;
class CLASS{
private:
int F,R,size,Q[];
public:
CLASS();
int insert(int);
int Deletee();
void Display();
};
CLASS::CLASS(){
F=R=-1;
cout<<"Enter Size :\n";
cin>>size;
}
int CLASS::insert(int n){
if((F==0 && R==size-1) || (F==R+1)){
cout<<"OVERFLOW\n";
return 0;
}
else if(R==size-1 && F!=0){
R=0;
}
else if(F==-1){
R=0;
F=0;
}
else{
R++;
}
Q[R]=n;
return 0;
}
int CLASS::Deletee(){
int deletedItem;
if(F==-1){
cout<<"UNDERFLOW\n";
}
deletedItem=Q[F];
if(F==R){
F=R=-1;
}
else if(F==size-1){
F=0;
}
else{
F++;
}
return 0;
}
void CLASS::Display(){
if(F==-1){
cout<<"Queue is Empty :\n";
}
else{
for(int i=F;i<=R;i++){
cout<<Q[i]<<"\t";
}
}
}
int main(){
CLASS obj;
int choice;
while(choice!=3){
cout<<"Enter 1 fro Insertion :\n";
cout<<"Enter 2 fro Deletion :\n";
cout<<"Enter 3 to Exit :\n";
cin>>choice;
switch(choice){
case 1:
int num;
cout<<"Enter Number to Insert :\n";
cin>>num;
obj.insert(num);
break;
case 2:
obj.Deletee();
cout<<"Queue after Deletion :\n";
obj.Display();
break;
}
}
return 0;
}