-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertion and deletion in Q.cpp
More file actions
78 lines (77 loc) · 1.13 KB
/
insertion and deletion in Q.cpp
File metadata and controls
78 lines (77 loc) · 1.13 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
#include<iostream>
using namespace std;
class Class{
private:
int F,R,s,Q[];
public:
Class();
int insert(int);
int deletee();
void display();
};
Class::Class(){
F=R=-1;
cout<<"Enter Size :\n";
cin>>s;
}
int Class::insert(int n){
if(R>=s){
cout<<"OVERFLOW\n";
//return 0;
}
else{
R++;
Q[R]=n;
if(F==-1)
F=0;
}
return 0;
}
int Class::deletee(){
int deletedItem;
if(F==-1){
cout<<"UNDERFLOW\n";
}
else{
deletedItem=Q[F];
if(F==R)
F=R=-1;
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 for Insertion\n";
cout<<"Enter 2 for Deletion\n";
cout<<"Enter 3 for 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<<"Array after deletion is :\n";
obj.display();
break;
}
}
return 0;
}