c++迭代器merge算法
#include<iostream>#include<iomanip>
#include<list>
#include<algorithm>
using namespace std;
class worker
{
char name[10];
int age;
double salary;
public:
worker(char *Name,int Age,double wage)
{
strcpy(name,Name);
age=Age;
salary=wage;
}
char *getname(){return name;}
int getage(){return age;}
double getsalary(){return salary;}
void display()
{ cout<<"姓名"<<setw(10)<<"年龄"<<setw(10)<<"薪金"<<endl;
cout<<*getname()<<setw(10)<<getage()<<setw(10)<<getsalary()<<endl;
}
};
void main()
{
worker a("tom",25,2000);
worker b("marry",26,2200);
worker c("lily",28,2800);
worker d("lucy",27,3000);
list<worker> l1,l2,l3;
list<worker>::iterator iter;
l1.push_back(a);
l1.push_back(b);
l2.push_back(c);
l2.push_back(d);
for(iter=l1.begin();iter!=l1.end();iter++)
(*iter).display();
for(iter=l2.begin();iter!=l1.end();iter++)
(*iter).display();
merge(l1.begin(),l1.end(),l2.begin(),l2.end(),l3);
for(iter=l3.begin();iter!=l3.end();iter++)
(*iter).display();
}
大家看一下这几行代码,能不能说一下merge合并时,
merge(l1.begin(),l1.end(),l2.begin(),l2.end(),l3);
for(iter=l3.begin();iter!=l3.end();iter++)
(*iter).display();
这样子为什么不可以?