Definitions of functions of the ArrayList are:
ArrayList();
void add(int n);
int deleteLast();
int size();
~ArrayList();
Some declarations:
int items;
int landex;
ArrayList doubleCapa(int* a, int l)
ArrayList halfCapa(int* a, int l)
int *List;
Below are the implementations of the above functions:
ArrayList()
{
int items = 0;
int landex=0;
int *List= new int [items];
}
//Add function
add(int n){
arrayList[landex]=n;
items++;
landex++;
if(items==landex)
{
arrayList=doubleCapa(arrayList, items);
}
}
//deleteLast()
int deleteLast()
{
int num=0;
if(arrayList!=0)
{
numD=arrayList[size];
arrayList[size]=NULL;
if(items<landex*2)
{
arrayList=halfSize(arrayList, landex);
}
}
else
{
cout << "Array contain no element";
}
return num;
}
//Size() functions
int size()
{
int num=0;
for(int i=0;i<arr.length;i++)
{
if(arr[i]!=NULL)
num++;
}
return num;
}
//
Comments
Leave a comment