-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathDeque - Double Ended Queue.cpp
85 lines (76 loc) · 1.96 KB
/
Deque - Double Ended Queue.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
/*
Deque - Double-Ended Queue implementation with C++ STL
Programmed by Hasan Abdullah
Contact: http://hellohasan.com
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int choise, data;
deque<int> myDeque;
deque<int>::iterator it;
while(true)
{
cout<<"\n\nChoose anyone:\n";
cout<<"1. push_front()\t2. push_back()\t3. pop_front()\t 4. pop_back()\n";
cout<<"5. front()\t 6. back()\t 7. clear()\t 8. show all elements\t 9. exit\n\n";
cin>>choise;
if(choise==1)
{
cout<<"Enter an integer to push it front\n";
cin>>data;
myDeque.push_front(data);
}
else if(choise==2)
{
cout<<"Enter an integer to push it back\n";
cin>>data;
myDeque.push_back(data);
}
else if(choise==3)
{
if(!myDeque.empty())
myDeque.pop_front();
else
cout<<"Deque is empty!\n";
}
else if(choise==4)
{
if(!myDeque.empty())
myDeque.pop_back();
else
cout<<"Deque is empty!\n";
}
else if(choise==5)
{
cout<<"Top front element is: "<<myDeque.front();
}
else if(choise==6)
{
cout<<"Top back element is: "<<myDeque.back();
}
else if(choise==7)
{
myDeque.clear();
cout<<"Deque is clear now!\n";
}
else if(choise==8)
{
if(!myDeque.empty())
{
cout<<endl<<"Full Deque is:\n";
for(it=myDeque.begin(); it != myDeque.end(); it++)
cout<<*it<<endl;
cout<<endl;
}
else
cout<<"Deque is empty!\n";
}
else if(choise==9)
break;
else
cout<<"Invalid input!\n";
}
return 0;
}