blob: 2bef2ef8fb172945cf77e9779535e7d74d3d6d2b (
plain)
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
|
#include <iostream>
#include <vector>
#include <list>
/*
*
* 9.26
*
*
*/
int main () {
int ia[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 55, 89 };
std::list<int> li;
std::vector<int> vi;
for(decltype(std::size(ia)) i = 0 ; i != std::size(ia) ; ++i) {
li.push_back(ia[i]);
vi.push_back(ia[i]);
}
auto beg = li.begin();
for( ; beg != li.cend() ; ) {
if(*beg % 2 == 1) {
beg = li.erase(beg);
} else {
++beg;
}
}
auto begv = vi.begin();
for( ; begv != vi.cend() ; ) {
if(*begv % 2 == 1) {
++begv;
} else {
begv = vi.erase(begv);
}
}
for(auto &a : li) {
std::cout << a << "\n";
}
std::cout << std::endl;
for(auto &a : vi) {
std::cout << a << "\n";
}
return 0;
}
|