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