3.) The function remove of the class arrayListType removes only thefirst occurrence of an element. Add the function removeAll as anabstract function to the class arrayListType, which would removeall occurrences of a given element. Also, write the definition ofthe function removeAll in the class unorderedArrayListType andwrite a program to test this function.
4.) Add the function min as an abstract function to the classarrayListType to return the smallest element of the list. Also,write the definition of the function min in the classunorderedArrayListType and write a program to test thisfunction.
5.) Add the function max as an abstract function to the classarrayListType to return the largest element of the list. Also,write the definition of the function max in the classunorderedArrayListType and write a program to test thisfunction.
#include
#include
#include \"arrayListType.h\"
using namespace std;
bool arrayListType::isEmpty() const
{
return (length == 0);
} //end isEmpty
bool arrayListType::isFull() const
{
return (length == maxSize);
} //end isFull
int arrayListType::listSize() const
{
return length;
} //end listSize
int arrayListType::maxListSize() const
{
return maxSize;
} //end maxListSize
void arrayListType::print() const
{
for (int i = 0; i < length; i++)
cout << list[i] << \" \";
cout << endl;
} //end print
bool arrayListType::isItemAtEqual(int location, int item)const
{
if (location < 0 || location >= length)
{
cout << \"The location of the item to be removed \"
<< \"is out of range.\" << endl;
return false;
}
else
return (list[location] == item);
} //end isItemAtEqual
void arrayListType::removeAt(int location)
{
if (location < 0 || location >= length)
cout << \"The location of the item to be removed \"
<< \"is out of range.\" << endl;
else
{
for (int i = location; i < length - 1; i++)
list[i] = list[i + 1];
length--;
}
} //end removeAt
void arrayListType::retrieveAt(int location, int& retItem)const
{
if (location < 0 || location >= length)
cout << \"The location of the item to be retrieved is \"
<< \"out of range\" << endl;
else
retItem = list[location];
} //end retrieveAt
// Part 1 - retrieve at as a value return function withassert
int arrayListType::retrieveAt(int location) const
{
assert(0 < location && location < length);
return list[location];
}
void arrayListType::clearList()
{
length = 0;
} //end clearList
arrayListType::arrayListType(int size)
{
if (size <= 0)
{
cout << \"The array size must be positive. Creating \"
<< \"an array of the size 100.\" << endl;
maxSize = 100;
}
else
maxSize = size;
length = 0;
list = new int[maxSize];
} //end constructor
//Add the function removeAll as an abstract function
//which would remove all occurrences of a given element
arrayListType::~arrayListType()
{
delete[] list;
} //end destructor
arrayListType::arrayListType(const arrayListType&otherList)
{
maxSize = otherList.maxSize;
length = otherList.length;
list = new int[maxSize]; Â Â //create the array
for (int j = 0; j < length; j++) //copy otherList
list[j] = otherList.list[j];
#include
#include \"unorderedArrayListType.h\"
using namespace std;
void unorderedArrayListType::insertAt(int location,
int insertItem)
{
if (location < 0 || location >= maxSize)
cout << \"The position of the item to be inserted \"
<< \"is out of range.\" << endl;
else if (length >= maxSize) //list is full
cout << \"Cannot insert in a full list\" << endl;
else
{
for (int i = length; i > location; i--)
list[i] = list[i - 1];Â Â //move the elements down
list[location] = insertItem; //insert the item at
//the specified position
length++;Â Â //increment the length
}
} //end insertAt
void unorderedArrayListType::insertEnd(int insertItem)
{
if (length >= maxSize) //the list is full
cout << \"Cannot insert in a full list.\" << endl;
else
{
list[length] = insertItem; //insert the item at the end
length++; //increment the length
}
} //end insertEnd
int unorderedArrayListType::seqSearch(int searchItem)const
{
int loc;
bool found = false;
loc = 0;
while (loc < length && !found)
if (list[loc] == searchItem)
found = true;
else
loc++;
if (found)
return loc;
else
return -1;
} //end seqSearch
void unorderedArrayListType::remove(int removeItem)
{
int loc;
if (length == 0)
cout << \"Cannot delete from an empty list.\" <else
cout << \"put the search and code here - use removeAt\"
<< \" in ArrayListType\" << endl;
} //end remove
//Finish implementing max and return the largest number
//int unorderedArrayListType::max() const
//{
// if (length == 0)
// {
// cout << \"The list is empty. \"
// << \"Cannot return the smallest element.\" <// exit(0);
// }
//
// int largest = list[0];
//} //end max
void unorderedArrayListType::replaceAt(int location, intrepItem)
{
if (location < 0 || location >= length)
cout << \"The location of the item to be \"
<< \"replaced is out of range.\" << endl;
else
list[location] = repItem;
} //end replaceAt
//
// Implement in class remove all occurences of a certainvalue
//void unorderedArrayListType::removeAll(int removeItem)
//{
// int loc;
//
// if (length == 0)
// cout << \"Cannot delete from an empty list.\" <// else
// {
// loc = 0;
//
// }
//} ////end removeAll
//int unorderedArrayListType::min() const
//{
// if (length == 0)
// {
// cout << \"The list is empty. \"
// << \"Cannot return the smallest element.\" <// exit(0);
// }
//
//
//
//} //end min
unorderedArrayListType::unorderedArrayListType(int size)
: arrayListType(size)
{
} //end constructor