#include <iostream>
#include <list>
#include <algorithm> //使用函数for_each
using namespace std;
void print(int& Ele){ //用于for_each中打印
cout<<Ele<<",";
}
int main()
{
list<int> L1,L2,L3;
L1.push_back(1);
L1.push_back(2);
L2.push_back(3);
L3.push_back(4);
L3.push_back(5);
cout<<"L1: ";
for_each(L1.begin(),L1.end(),print);
cout<<endl;
cout<<"L2: ";
for_each(L2.begin(),L2.end(),print);
cout<<endl;
cout<<"L3: ";
for_each(L3.begin(),L3.end(),print);
cout<<endl;
cout<<"L1 合并 L2: ";
L1.splice(L1.end(),L2); //将L2接到L1后面
for_each(L1.begin(),L1.end(),print);
cout<<endl;
cout<<"L1 合并 L3: ";
L1.splice(L1.end(),L3,L3.begin(),L3.end()); //将L3连接到L1后面
for_each(L1.begin(),L1.end(),print);
cout<<endl;
return 0;
}
C++ STL list的成员函数splice的使用
最新推荐文章于 2024-10-05 10:33:20 发布