An arrayList is one of the most important data structures used in many applications. Define and show the implementation of the functions of an arrayList
Functions of ArrayLists:
ArrayList();
~ArrayList();
void add(int n);
int size();
int deleteLast();
Some declarations for implementations of the above functions:
int data;
int item_andex;
ArrayList doubleCapacity(int* x, int y)
ArrayList halfCapacity(int* x, int y)
int *arr_List;
Implementations of the functions of ArrayList:
ArrayList()
{
int data = 0;
int item_andex=0;
int *arr_List= new int [data];
}
//Insertion function of ArrayList
add(int item){
arr_List[item_andex]=item;
data++;
item_andex++;
if(data==item_andex)
{
arr_List=doubleCapacity(arr_List, data);
}
}
//Deleting function of ArrayList
int deleteLast()
{
int count=0;
if(arrayList!=0)
{
count=arr_List[size];
arr_List[size]=NULL;
if(items<item_andex*2)
{
arr_List=halfCapacity(arr_List, item_andex);
}
}
else
{
cout << "Array is empty\n";
}
return count;
}
//ArrayList Size() function
int size()
{
int count=0;
for(int x=0;x<arr.length;x++)
{
if(arr[x]!=NULL)
count++;
}
return count;
}
Comments
Leave a comment