C++merge関数

3514 ワード

C++merge関数
  ,merge()        L1,L2    ,      merge()  。

1. worker 。
bool operator<(const worker & kk)
{
return this->age < kk.getAge();
}
2. L1.merge(L2) 。

L1.sort();
L2.sort();

, 。
  :        。
, , 。
#include <iostream>
#include <list>
#include <iomanip>
using namespace std;

int main()
{
//
int A1[]={1,2,3,4,5,6};
int A2[]={2,4,6,8,9,10};
//
list<int> iL1(A1, A1+6);
list<int> iL2(A2, A2+6);
iL1.merge(iL2); // , ,
list<int>::iterator it = iL1.begin();
while(it!=iL1.end())
{
cout<<setw(3)<<*it++;
}
cout<<endl;
system("pause");
return 0;
}

1 2 2 3 4 4 5 6 6 8 9 10