STL List(2)

View Code
 1 #include<iostream>
2 #include<list>
3
4 using namespace std;
5
6 void PrintListContent(const list<int>& listInput);
7
8 int main()
9 {
10
11
12 std::list<int> a;
13 a.push_front(4);
14 a.push_front(3);
15
16 list<int>::iterator iElementValueTwo;
17
18 iElementValueTwo=a.insert(a.begin(),2);//不能用push,push不返回迭代器,inser返回迭代器
19
20 a.push_front(1);
21 a.push_front(0);
22
23 PrintListContent(a);
24
25 cout << endl;
26
27 a.erase(a.begin(),iElementValueTwo);//从那里到哪里删除
28 PrintListContent(a);
29
30 a.erase(iElementValueTwo,a.end());
31 PrintListContent(a);
32
33
34
35 return 0;
36 }
37
38 void PrintListContent(const list<int>& listInput)
39 {
40
41 cout << "{" ;
42 std::list<int>::const_iterator iter;
43 for(iter = listInput.begin(); iter != listInput.end(); ++iter)
44 cout << *iter << " ";
45 cout << "}" << endl;
46
47
48 }
posted @ 2012-03-27 23:25  uniquews  阅读(127)  评论(0编辑  收藏  举报