-
Notifications
You must be signed in to change notification settings - Fork 0
/
DEQUE USING STL
82 lines (72 loc) · 1.42 KB
/
DEQUE USING STL
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
// Write C++ program using STL for Dqueue (Double ended queue)
#include<iostream>
#include<string.h>
#include<deque>
using namespace std;
class Dequeue
{
public :
int a;
deque <int> s;
deque <int> :: iterator itr;
void push_front()
{
cout<<"\n Enter a number : ";
cin>>a;
s.push_front(a);
}
void push_back()
{
cout<<"\n Enter a number : ";
cin>>a;
s.push_back(a);
}
void pop_back()
{
itr=s.end();
itr--;
s.pop_back();
cout<<"\n The element popped out of the queue is "<<*itr;
}
void pop_front()
{
itr=s.begin();
s.pop_front();
cout<<"\n The element popped out of the queue is "<<*itr;
}
void displayqueue()
{
cout<<"\n The elements in the queue are : "<<"\n";
for(itr=s.begin() ; itr!=s.end() ; itr++)
{
cout<<*itr<<"\t";
}
}
};
int main()
{
Dequeue p;
int choice;
char ans;
do
{
cout<<"\n 1. Add element from front \n 2. Add element from behind \n 3. Delete element front front \n 4. Delete element from behind \n 5. Display queue elements";
cout<<"\n Enter the operation you want to perform : ";
cin>>choice;
switch(choice)
{
case 1 : p.push_front();
break;
case 2 : p.push_back();
break;
case 3 : p.pop_front();
break;
case 4 : p.pop_back();
break;
case 5 : p.displayqueue();
break;
}
cout<<"\n Do you want to perform any other operation ?";
cin>>ans;
}while(ans=='Y' || ans=='y');
}