-
Notifications
You must be signed in to change notification settings - Fork 2
/
41.cpp
58 lines (48 loc) · 1.47 KB
/
41.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
#include<iostream>
#include<deque>
#include<vector>
int main()
{
//program to understand the deque (double ended queue)
std::deque<char> d;
std::vector<char> v = {'A', 'B', 'C', 'D', 'E', 'F', 'G'};
std::vector<char>::iterator p;
//inserting in a double ended queue using a push_back function
for( p = v.begin();p != v.end();p++)
{
d.push_back(*p);
}
//printing the elements of the deque
std::deque<char>::iterator it = d.begin();
std::cout<<"Elements in deque : ";
while(it!=d.end())
{
std::cout<<*it<<" ";
it++;
}
std::cout<<std::endl;
//size of the deque
std::cout<<"Size : "<<d.size()<<std::endl;
//max size of the deque
std::cout<<"Max size : "<<d.max_size()<<std::endl;
//finding the first element of the deque
std::cout<<"Front element : "<<d.front()<<std::endl;
//finding the last element
std::cout<<"Last element : "<<d.back()<<std::endl;
//popping the front element of the deque
d.pop_front();
std::cout<<"Front element : "<<d.front()<<std::endl;
//popping the last element of the deque
d.pop_back();
std::cout<<"Last element : "<<d.back()<<std::endl;
//printing elements of the deque in reverse order from front
std::deque<char>::reverse_iterator t = d.rbegin();
std::cout<<"Elements of the deque : ";
while(t!=d.rend())
{
std::cout<<*t<<" ";
t++;
}
std::cout<<std::endl;
return 0;
}