Answer to Question #227453 in C++ for Sandile

Question #227453
Define and show the implementation of the functions of an arrayList.
1
Expert's answer
2021-08-19T03:22:07-0400
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;


}
//

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS