STL List(3)

View Code
 1 #include<iostream>
2 #include<list>
3
4
5 using namespace std;
6
7 void PrintListContent(const list<int>& listInput);
8
9 int main()
10 {
11
12 std::list<int> a;
13
14 a.push_front(5);
15 a.push_front(9);
16 a.push_front(21);
17 a.push_front(16);
18 a.push_front(8);
19
20 PrintListContent(a);
21
22 a.sort();//排序
23 PrintListContent(a);
24
25 a.reverse();//翻转
26 PrintListContent(a);
27
28
29
30 return 0;
31
32
33
34 }
35
36
37
38
39
40 void PrintListContent(const list<int>& listInput)
41 {
42
43 cout << "{" ;
44 std::list<int>::const_iterator iter;
45 for(iter = listInput.begin(); iter != listInput.end(); ++iter)
46 cout << *iter << " ";
47 cout << "}" << endl;
48
49
50 }
posted @ 2012-03-27 23:27  uniquews  阅读(128)  评论(0编辑  收藏  举报