Rather than enhancing the Unsorted List ADTs by adding a mem

Rather than enhancing the Unsorted List ADTs by adding a member function IsThere, you decide to write a client function to do the same task. a. Write the specifications for this function. b. Write the function definition. c. Write a paragraph comparing the client function and the member function (Exercise 1) for the same task. d. Describe this function in terms of Big-O.

The function language should be in C++

Solution

a) It should be a boolean fuction which returns true if found and false elsewise. It will take the list as the input and the number to be searched for.

b) boolean Isthere(ArrayList a , int n)

{int i;

for(i=0;i< a.size();i++)

{

if(a[i]==n)

return true;

}

return false;

}

c) Since, it is an unsorted list client function or the member function does not make any difference and the algorithm should go to each and every element and check if the element is present. Hence it will take O(n) time

d)O(n). I have explained in the previous step

Rather than enhancing the Unsorted List ADTs by adding a member function IsThere, you decide to write a client function to do the same task. a. Write the specif

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site