Question: 1. Templates. The code below contains a silly sort method. a) What is the time complexity? Why? b) Modify it so that it can sort

1. Templates. The code below contains a silly sort method.

a) What is the time complexity? Why?

b) Modify it so that it can sort "anything", for example strings. This means: make it a templated function.

c) In main(), introduce a 3 element array of these objects: struct bloodtype { char btype; bool posneg; }; and sort the array using ins_sort. You may need to modify the struct.

Your code does not need to print the resulting array.

void ins_sort(int arr[], int asize) { int tmp; int i,j; for (i = 1; i < asize; i++) { j = i; while (j > 0 && arr[j] < arr[j-1]) { tmp = arr[j]; arr[j] = arr[j-1]; arr[j-1] = tmp; j--; } } }

Note: I need my answer on C++ coding..please do it fast its urgent.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!