# include<iostream>
# include<list>
using namespace std;
void printList(const list<int> &L)
{
for (list<int>::const_iterator it = L.begin(); it != L.end(); it++)
{
cout << *it<<" ";
}
cout << endl;
}
void test02()
{
list<int>L1;
L1.push_back(10);
L1.push_back(20);
L1.push_back(30);
L1.push_back(40);
L1.push_back(50);
printList(L1);
list<int> L2;
L2 = L1;
printList(L2);
list<int> L3;
L3.assign(L1.begin(), L1.end());
printList(L3);
list<int>L4;
L4.assign(10,1000);
printList(L4);
}
void test03() //交换
{
list<int>L1;
L1.push_back(10);
L1.push_back(20);
L1.push_back(30);
L1.push_back(40);
L1.push_back(50);
list<int> L2(10, 100);
cout << "交换前:" << endl;
printList(L1);
printList(L2);
L1.swap(L2);
cout << "交换后:" << endl;
printList(L1);
printList(L2);
}
int main()
{
test03();
system("pause");
return 0;
}