-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdynamic_array.cpp
65 lines (50 loc) · 1.13 KB
/
dynamic_array.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
#include <iostream>
#include <vector>
#include <deque>
#include <numeric>
#include <algorithm>
#include <functional>
using namespace std;
template <typename T>
void print(T a) {
if (!a.empty()) {
for (const auto &x : a) {
cout << x << ' ';
}
cout << '\n';
} else {
cout << "Empty Container\n";
}
}
int main() {
vector<int> a = {1, 2, 3, 4, 5};
vector<int> b(a.begin(), a.begin() + 3);
vector<int> c{1, 2, 3, 4, 5};
print(a);
print(b);
print(c);
int x = 1.1;
int y{1};
cout << "(x, y): (" << x << ", " << y << ")\n";
deque<int> d(7);
iota(d.begin(), d.end(), 9);
for (int i = 0; i < (int) d.size(); i++) {
cout << d[i] << ' ';
}
cout << '\n';
d.pop_front();
d.push_front(1);
d.pop_back();
d.push_back(100);
for (int i = 0; i < (int) d.size(); i++) {
cout << d[i] << ' ';
}
cout << '\n';
// reverse(d.begin(), d.end());
// print(d);
sort(d.begin(), d.begin() + 4, greater<int>());
print(d);
sort(d.begin() + 2, d.begin() + 4, less<int>());
print(d);
return 0;
}