The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. Also, write a program to test your function. Use the class unorderedArrayListType to test your function.

Respuesta :

Answer:

int retrieveAt(int location, array){

   // Function to retrieve the element from the list at the position

   // specified by the location

   if (location <= array.size() - 1){

       return array[location];

   } else{

       cout<<"Location out of range";

       assert(); // Assuming the assert function is defined in the program.

   }

}

Explanation:

The void retrieveAt function is converted to a return function that returns the integer item of the array given the location and the array variable as arguments. The assert function is used to terminate the program.