-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlistrmv.cpp
More file actions
40 lines (34 loc) · 990 Bytes
/
Copy pathlistrmv.cpp
File metadata and controls
40 lines (34 loc) · 990 Bytes
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
//
// Created by 赵健 on 2021/8/17.
//
#include "listrmv.h"
#include "../../utils/Utils.h"
#include <iostream>
#include <algorithm>
#include <list>
const int LIM = 10;
void listrmv::test() {
using namespace std;
int ar[LIM] = {4, 5, 4, 2, 2, 3, 4, 8, 1, 4};
list<int> la(ar, ar + LIM);
list<int> lb(la);
cout << "Original list contents:\n\t";
for_each(la.begin(), la.end(), Utils::ShowInt);
cout << endl;
la.remove(4);
cout << "After using them remove() method:\n";
cout << "la:\t";
for_each(la.begin(), la.end(), Utils::ShowInt);
cout << endl;
list<int>::iterator last;
last = remove(lb.begin(), lb.end(), 4);
cout << "After using the remove() function:\n";
cout << "lb:\t";
for_each(lb.begin(), lb.end(), Utils::ShowInt);
cout << endl;
lb.erase(last, lb.end());
cout << "After using the erase() method:\n";
cout << "lb:\t";
for_each(lb.begin(), lb.end(), Utils::ShowInt);
cout << endl;
}