forked from kushal-156/web-page
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue_using_array.cpp
More file actions
73 lines (65 loc) · 1.56 KB
/
queue_using_array.cpp
File metadata and controls
73 lines (65 loc) · 1.56 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
#include<iostream>
#include<vector>
using namespace std;
class Menu{
protected:
int n,elem,i;
vector<int> vec;
public:
void menu(){
cout<<endl<<"Choose an option "<<endl;
cout<<"1. Add an element. "<<endl;
cout<<"2. Remove an element. "<<endl;
cout<<"3. Return queue. "<<endl;
cout<<"4. Exit. "<<endl;
cin>>n;
}
};
class Flow :public Menu{
public:
void work();
void add()
{
cout<<"enter element to add :"<<endl;
cin>>elem;
vec.push_back(elem);
}
void remove();
void print();
};
void Flow :: remove(){
if (vec.size()==0)cout<<"queue is empty. "<<endl;
else {
for (i=1;i<=vec.size();i++){
if (i==vec.size())
{
vec.pop_back();
break;
}
vec[i-1]=vec[i];
}
}
}
void Flow :: print(){
cout<<endl<<endl;
for (i=0;i<vec.size();i++){
cout<<vec[i]<<" ";
}
cout<<endl<<endl<<endl;
}
void Flow:: work(){
n=6;
while(n!=4){
menu();
if (n==1) add();
else if (n==2) remove();
else if (n==3) print();
else if (n==4) break;
else cout<<"enter valid option. "<<endl;
}
}
int main(){
Flow object;
object.work();
return 0;
}