#include <iostream>
#include <list>
#include <algorithm>
#include <iterator>
using namespace std;
int main(){
int ary[] = { 2, 5, 9, 7, 2, 7, 6, 5 };
list<int> list1(ary, ary + 4);
list<int> list2(ary + 4, ary + 8);;
cout << "list1:";
copy(list1.begin(), list1.end(), ostream_iterator<int>(cout, " "));
cout << endl;
cout << "list2:";
copy(list2.begin(), list2.end(), ostream_iterator<int>(cout," "));
cout << endl;
list1.sort();
list2.sort();
list1.merge(list2);
cout << "After\"list1.merge(list2)\":" << endl;
cout << "list1:";
copy(list1.begin(),list1.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "size of list1 = " << list1.size() << endl;
cout << "list2:";
copy(list2.begin(), list2.end(),ostream_iterator<int>(cout," "));
cout << endl;
cout << "size of list2 = " << list2.size() << endl;
return 0;
}
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步