#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
int main()
{
list intList1,intList2,intList3,intList4;
ostream_iterator screen(cout," ");
//迭代器输出元素以空格为间隔
intList1.push_back(10);
for(int i=0;i<10;i++)
intList1.push_back(10+i);
cout<<"intList1:"< copy(intList1.begin(),intList1.end(),screen);
cout<
intList2=intList1;
cout<<"intList2:"< copy(intList2.begin (),intList2.end (),screen);
cout<
intList1.unique ();//删除连续的重复项
cout<<"After removing the consecutive duplicates,"<<" intList1:"< copy(intList1.begin (),intList1.end(),screen);
cout<
intList1.push_back (5);
cout<<"After push_back(5):"< copy(intList1.begin(),intList1.end(),screen);
cout<
intList1.sort ();
cout<<"After sorting:"< copy(intList1.begin(),intList1.end(),screen);
cout<
intList3.push_back (13);
intList3.push_back (23);
intList3.push_back (25);
intList3.push_back (136);
intList3.push_back (198);
intList3.push_back (89);
intList3.push_back (45);
cout<<"intList3:"< copy(intList3.begin(),intList3.end(),screen);
cout<
intList4.push_back (-2);
intList4.push_back (-7);
intList4.push_back (-8);
intList4.push_back (-36);
cout<<"intList4:"< copy(intList4.begin(),intList4.end(),screen);
cout<
intList3.splice (intList3.begin (),intList4);
cout<<"After moving the elements of intList4 into intList3, intList3:"< copy(intList3.begin(),intList3.end(),screen);
cout<
intList3.sort ();
cout<<"After sorting,intList3:"< copy(intList3.begin(),intList3.end(),screen);
cout<
intList1.merge (intList3);
cout<<"After merging intList1 and intList3,intList1:"< copy(intList1.begin(),intList1.end(),screen);
cout<
intList1.unique ();
cout<<"After unique(),intList1:"< copy(intList1.begin(),intList1.end(),screen);
cout<
return 0;
}
运行结果:
阅读(817) | 评论(0) | 转发(0) |