-
Notifications
You must be signed in to change notification settings - Fork 246
/
9.26.cpp
46 lines (38 loc) · 1010 Bytes
/
9.26.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
#include <vector>
#include <list>
#include <iterator>
#include <iostream>
int main() {
int ia[] = {0, 1, 1, 2, 3, 5, 8, 13, 21, 55, 89};
std::vector<int> iv(std::begin(ia), std::end(ia));
std::list<int> il(std::begin(ia), std::end(ia));
std::cout << "Before erase:" << std::endl;
std::cout << "vector iv: ";
for (const auto &i: iv)
std::cout << i << " ";
std::cout << std::endl;
std::cout << "list il: ";
for (const auto &i: il)
std::cout << i << " ";
std::cout << std::endl;
for (auto it = iv.begin(); it != iv.end(); )
if (*it % 2)
++it;
else
it = iv.erase(it);
for (auto it = il.begin(); it != il.end(); )
if (*it % 2)
it = il.erase(it);
else
++it;
std::cout << "After erase:" << std::endl;
std::cout << "vector iv: ";
for (const auto &i: iv)
std::cout << i << " ";
std::cout << std::endl;
std::cout << "list il: ";
for (const auto &i: il)
std::cout << i << " ";
std::cout << std::endl;
return 0;
}