-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue through array.cpp
86 lines (77 loc) · 1.56 KB
/
queue through 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
85
86
#include <iostream>
using namespace std;
int a[100];
int f = -1;
int r = -1;
void insert(int value) {
if ((f == -1) && (r == -1)) {
f = 0;
r = 0;
a[f] = value;
} else {
cout << "queue overflow" << endl;
}
}
void del() {
if ((f == -1) && (r == -1)) {
cout << "empty" << endl;
} else {
f++;
}
}
void display() {
if (f >= 0) {
cout << "the elements are " << endl;
for (int i = r; i >= f; i--) {
cout << a[i] << " ";
}
cout << endl;
} else {
cout << "queue is empty" << endl;
}
}
int main() {
int arr[20];
int ch;
int n;
int p;
cout<<"enter how many numbers you want to insert: ";
cin>>p;
for(int i = 0;i<p;i++){
cin>>arr[i];
}
for(int i = 0;i<p;i++){
cout<<arr[i]<<" ";
}
cout<<endl;
cout << "1.insert" << endl;
cout << "2.delete" << endl;
cout << "3.display" << endl;
cout << "choose the option" << endl;
cin >> ch;
switch (ch) {
case 1: {
cout << "enter the element to insert" << endl;
cin >> n;
insert(n);
for(int i = 0;i<p;i++){
cout<<arr[i]<<" "<<endl;
}
break;
}
case 2: {
del();
for(int i = 0;i<p;i++){
cout<<arr[i]<<" "<<endl;
}
break;
}
case 3: {
display();
break;
}
default:
cout << "invalid choice";
}
return 0;
}