-
Notifications
You must be signed in to change notification settings - Fork 2
/
14.Deque.cpp
134 lines (112 loc) · 1.96 KB
/
14.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//14
#include<iostream>
#include<deque>
using namespace std;
class dequed
{
private:
deque<int>d1;
deque<int>::iterator ptr;
public:
//---------------------------------------------------
void add_front()
{
int n;
while(1)
{
cout<<"Enter number : ";
cin>>n;
if(n == 0)
break;
d1.push_front(n);
}
}
//---------------------------------------------------
void add_back()
{
int n;
while(1)
{
cout<<"Enter number : ";
cin>>n;
if(n == 0)
break;
d1.push_back(n);
}
}
//---------------------------------------------------
void delete_front()
{
if(d1.size()==0)
{
cout<<"\nQUEUE IS EMPTY!!"<<endl;
return;
}
d1.pop_front();
cout<<"\nELEMENT DELETED";
}
//---------------------------------------------------
void delete_back()
{
if(d1.size() == 0)
{
cout<<"\nQUEUE IS EMPTY!!"<<endl;
return;
}
d1.pop_back();
cout<<"\nELEMENT DELETED";
}
//---------------------------------------------------
void display()
{
ptr=d1.begin();
// cout<<"1st = "<<*ptr<<endl;
if(d1.size()==0)
{
cout<<"\nQUEUE IS EMPTY!!"<<endl;
return;
}
for(;ptr!=d1.end();ptr++)
{
cout<<"Number : "<<*ptr<<endl;
}
}
//---------------------------------------------------
};
main()
{
dequed d;
int op=-1;
while(op!=0)
{
cout<<"\n\n1.ADD FROM FRONT";
cout<<"\n2.ADD FROM BACK";
cout<<"\n3.DELETE FROM FRONT";
cout<<"\n4.DELETE FROM BACK";
cout<<"\n5.DISPLAY";
cout<<"\n6.EXIT";
cout<<"\n\nENTER CHOICE : ";
cin>>op;
switch(op)
{
case 1:
d.add_front();
break;
case 2:
d.add_back();
break;
case 3:
d.delete_front();
break;
case 4:
d.delete_back();
break;
case 5:
d.display();
break;
case 6:
op=0;
break;
}
}
}