Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started