forked from SilverMaple/STLSourceCodeNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_3_5_list-test.cpp
More file actions
54 lines (44 loc) · 1.19 KB
/
4_3_5_list-test.cpp
File metadata and controls
54 lines (44 loc) · 1.19 KB
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
// file: list-test.cpp
#include <list>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int i;
list<int> ilist;
cout << "size=" << ilist.size() << endl;
for (int j = 0; j < 5; j++) {
ilist.push_back(j);
}
cout << "size=" << ilist.size() << endl;
list<int>::iterator ite;
for (ite = ilist.begin(); ite != ilist.end(); ++ite) {
cout << *ite << ' ';
}
cout << endl;
ite = find(ilist.begin(), ilist.end(), 3);
if (ite != ilist.end()) {
ilist.insert(ite, 99);
}
cout << "size=" << ilist.size() << endl;
cout << *ite << endl;
for (ite = ilist.begin(); ite != ilist.end(); ++ite) {
cout << *ite << ' ';
}
cout << endl;
ite = find(ilist.begin(), ilist.end(), 1);
if (ite != ilist.end()) {
cout << *(ilist.erase(ite)) << endl;
}
for (ite = ilist.begin(); ite != ilist.end(); ++ite) {
cout << *ite << ' ';
}
cout << endl;
int iv[5] = { 5,6,7,8,9 };
list<int> ilist2(iv, iv+5);
//目前,ilist的内容为 0 2 99 3 4
ite = find(ilist.begin(), ilist.end(), 99);
ilist.splice(ite, ilist2);
ilist.reverse();
ilist.sort()
}