主题:[讨论]请帮忙
#include<iostream>
#include<list>
#include"d_random.h"
using namespace std;
template <typename T>
void addList(const list<T>& list1,const list<T>& list2,list<T>& list3)
{
list<T>::iterator iter1;
iter1=list1.begin();
for(int a=0;a<list1.size();a++)
{
list3.push_back(*iter1);
iter1++;
}
list<T>::iterator iter2;
iter2=list2.begin();
for(int b=0;b<list2.size();b++)
{
list3.push_back(*iter2);
iter2++;
}
}
int main()
{
randomNumber rnd;
list<int> listL,listM,listN;
int i,j;
cout<<"size of listL(between 1 and 5):";
cin>>i;
for(int a=0;a<i;a++)
{
listL.push_back(rnd.random(99)+0);
}
cout<<"\nsize of listM(between 1 and 10):";
cin>>j;
for(int b=0;b<j;b++)
{
listM.push_back(rnd.random(199)+100);
}
addList(listL,listM,listN);
list<int>::iterator listIter;
for(listIter=listN.begin();listIter!=listN.end();listIter++)
{
cout<<"the new listN is:"<<*listIter<<" ";
}
}
#include<list>
#include"d_random.h"
using namespace std;
template <typename T>
void addList(const list<T>& list1,const list<T>& list2,list<T>& list3)
{
list<T>::iterator iter1;
iter1=list1.begin();
for(int a=0;a<list1.size();a++)
{
list3.push_back(*iter1);
iter1++;
}
list<T>::iterator iter2;
iter2=list2.begin();
for(int b=0;b<list2.size();b++)
{
list3.push_back(*iter2);
iter2++;
}
}
int main()
{
randomNumber rnd;
list<int> listL,listM,listN;
int i,j;
cout<<"size of listL(between 1 and 5):";
cin>>i;
for(int a=0;a<i;a++)
{
listL.push_back(rnd.random(99)+0);
}
cout<<"\nsize of listM(between 1 and 10):";
cin>>j;
for(int b=0;b<j;b++)
{
listM.push_back(rnd.random(199)+100);
}
addList(listL,listM,listN);
list<int>::iterator listIter;
for(listIter=listN.begin();listIter!=listN.end();listIter++)
{
cout<<"the new listN is:"<<*listIter<<" ";
}
}