#include <iostream>
using namespace std;
template<class T>class Lista{
private:
T *itens;
int ultimo, maxTam;
public:
Lista(int maxTam);
void insere(T item);
T get(int i);
T MisturaListas(Lista<T> l1, Lista<T> l2, Lista<T> l3);
};
template <class T> Lista<T>::Lista(int maxTam){
this->maxTam = maxTam;
this->itens = new T[maxTam];
this->ultimo = 0;
}
template <class T> void Lista<T>::insere(T item){
if(ultimo == maxTam){
cout<< "Lista Cheia!"<<endl;
}else{
this->itens[this->ultimo] = item;
this->ultimo++;
}
}
template<class T> T Lista<T>::get(int i){
return itens[i];
}
//Aqui o protótipo do método.
template<class T> T Lista<T>::MisturaListas(Lista<T> l1, Lista<T> l2, Lista<T> l3){
for(int i = 0; i < 5; i++){
l3.insere(l1.get(i));
l3.insere(l2.get(i));
}
}
int main()
{
Lista<int> lista1(5); //esta lista ja está cheia
lista1.insere(0);
lista1.insere(1);
lista1.insere(2);
lista1.insere(3);
lista1.insere(4);
for(int _i = 0; _i < 5; _i++){
cout<<lista1.get(_i);
}
cout<<endl;
Lista<int> lista2(5); //esta lista já está cheia
lista2.insere(5);
lista2.insere(6);
lista2.insere(7);
lista2.insere(8);
lista2.insere(9);
for(int _i = 0; _i < 5; _i++){
cout<<lista2.get(_i);
}
Lista<int> lista3(10); //esta lista deve receber o conteudo das duas listas anteriores intercalados.
lista3.MisturaListas(lista1, lista2, lista3);
cout<<endl;
for(int _i = 0; _i < 10; _i++){
cout<<lista3.get(_i);
}
cout << endl << "Hello world!" << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPGNsYXNzIFQ+Y2xhc3MgTGlzdGF7CiAgICBwcml2YXRlOgogICAgICAgIFQgKml0ZW5zOwogICAgICAgIGludCB1bHRpbW8sIG1heFRhbTsKCiAgICBwdWJsaWM6CiAgICAgICAgTGlzdGEoaW50IG1heFRhbSk7CiAgICAgICAgdm9pZCBpbnNlcmUoVCBpdGVtKTsKICA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