adding two array list with operator+ O_O
/*+ operatoru iki array list i birlestirecek sekilde (ornek:
lis1+list2 : list2 list1 in sonuna eklenecek) overload ediniz.
const List List::operator+(const List& input_list){*/
#include<iostream
using namespace std;
class Liste
{
public:
Liste(int = 10);
Liste(const Liste &);
Liste& operator+(Liste &);
int getSize() {return size;}
private:
int *ptr;
int size;
};
Liste::Liste(int aSize)
{
size=(aSize 0 ? aSize : 10 );
ptr = new int[size];
for(int i=0; i<size; i++)
{
ptr[i]=0;
}
}
Liste::Liste(const Liste &p)
{
size=p.size;
ptr = new int[size];
for(int i=0; i<size; i++)
{
ptr[i]=p.ptr[i];
}
}
Liste& Liste::operator+(Liste &d)
{
int i=size;
size=size+d.size;
Liste *c= new Liste(size);
Liste& result=*c;
int k=0;
for(k=0; k<i; k++)
{
c-ptr[k]=ptr[k];
}
k=0;
for(i; i<size; i++)
{
c-ptr[i]=d.ptr[k];
}
for(k=0; k<size; k++)
{
ptr[k]=c-ptr[k]; //copy to first array c=a+b - a has
got all the numbers
}
return result;
}
int main()
{
Liste a(5),b(4);
Liste& c=a+b;
cout<<c.getSize()<<endl;
return 0;
}