-
Notifications
You must be signed in to change notification settings - Fork 0
/
deque.cpp
88 lines (77 loc) · 1.73 KB
/
deque.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
87
88
#include<iostream>
#include<deque>
using namespace std;
int main()
{
deque<int>ob;
deque<int>::iterator it;
int ele,ch,e=0;
while(e==0)
{
cout<<"1.INSERT ELEMENT AT THE BACK\n";
cout<<"2.INSERT ELEMENT AT THE FRONT\n";
cout<<"3.DELETE ELEMENT AT THE BACK\n";
cout<<"4.DELETE ELEMENT AT THE FRONT\n";
cout<<"5.GET FRONT ELEMENT\n";
cout<<"6.GET BACK ELEMENT\n";
cout<<"7.GET SIZE OF QUEUE\n";
cout<<"8.DISPLAY ELEMENTS OF QUEUE\n";
cout<<"ENTER YOUR CHOICE\n";
cin>>ch;
switch(ch)
{
case 1:
{
cout<<"ENTER ELEMENT OT BE INSERTED\n";
cin>>ele;
ob.push_back(ele);
break;
}
case 2:
{
cout<<"ENTER ELEMENT TO BE INSERTED\n";
cin>>ele;
ob.push_front(ele);
break;
}
case 3:
{
ele=ob.back();
ob.pop_back();
break;
}
case 4:
{
ele=ob.front();
ob.pop_front();
break;
}
case 5:
{
ele=ob.front();
cout<<ele<<endl;
break;
}
case 6:
{
ele=ob.back();
cout<<ele<<endl;
break;
}
case 7:
{
int s=ob.size();
cout<<s<<endl;
break;
}
case 8:
for(it=ob.begin(); it!=ob.end(); it++)
{
cout<<*it<<"\t";
}
cout<<"\n";
break;
}
}
return 0;
}