-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDeque
More file actions
59 lines (47 loc) · 1.36 KB
/
Deque
File metadata and controls
59 lines (47 loc) · 1.36 KB
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
/* *********************************************************
* KNOWLEDGE CENTER
* st::Deque
* Detailed Video Explanation: https://youtu.be/3U_Eg9WdGr0
********************************************************** */
#include <iostream>
#include <deque>
using namespace std;
int main() {
deque<int> d = {1, 2, 3, 4, 5};
cout << "size = " << d.size() << endl;
cout << "Third element = " << d[2] << endl;
cout << d.front() << ", " << d.back() << endl;
for(deque<int>::iterator it = d.begin(); it != d.end(); ++it)
cout << *it << "\t";
cout << endl;
for(deque<int>::reverse_iterator it = d.rbegin(); it != d.rend(); ++it)
cout << *it << "\t";
cout << endl;
d.push_back(100);
d.push_back(200);
d.push_front(-100);
d.push_front(-200);
for(deque<int>::iterator it = d.begin(); it != d.end(); ++it)
cout << *it << "\t";
cout << endl;
d.pop_back();
d.pop_front();
for(deque<int>::iterator it = d.begin(); it != d.end(); ++it)
cout << *it << "\t";
cout << endl;
d.clear();
for(deque<int>::iterator it = d.begin(); it != d.end(); ++it)
cout << *it << "\t";
cout << endl;
return 0;
}
/*
size()
=, []
front(), back()
empty()
begin(), end(), rbegin(), rend()
insert(), erase()
clear()
push_back(), push_front(), pop_back(), pop_front()
*/