I need a working code for a solution to this problem using v
I need a working code for a solution to this problem using visual studio 2015:
C++ Programming (7th Edition)
Chapter 18, Problem 12PE
Sort an array of 10,000 elements using the quick sort algorithm as follows: Sort the array using pivot as the middle element of the array. Sort the array using pivot as the median of the first, last, and middle elements of the array. Sort the array using pivot as the middle element of the array. However, when the size of any sublist reduces to less than 20, sort the sublist using an insertion sort. Sort the array using pivot as the median of the first, last, and middle elements of the array. When the size of any sublist reduces to less than 20, sort the sublist using an insertion sort. Calculate and print the CPU time for each of the preceding four steps. To find the current CPU time, declare a variable, say, x, of type clock_t. The statement x = clock(); stores the current CPU time in x. You can check the CPU time before and after a particular phase of a program. Then, to find the CPU time for that particular phase of the program, subtract the before time from the after time. Moreover, you must include the header file ctime to use the data type clock_t and the function clock. Use a random number generator to initially fill the array.Solution
Implementing both quicksort and insertionsort
void quickSort(int arr[], int left, int right) {
int i = left, j = right;
int tmp;
int pivot = arr[(left + right) / 2];
// int pivot = (arr[left]+arr[right]+arr[(left+right)/2])/3
while (i <= j) {
while (arr[i] < pivot)
i++;
while (arr[j] > pivot)
j--;
if (i <= j) {
tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
i++;
j--;
}
};
if (left < j)
quickSort(arr, left, j);
if (i < right)
quickSort(arr, i, right);
}
void insertionSort(int arr[], int left, int right) {
for (i = left; i < right+1; i++)
{
temp=a[i];
for (j = i; j>=left && temp<a[j]; j--)
{
if (a[j] < a[j-1])
{
a[j+1]=a[j]; // forward move
}
a[j+1]=temp; // insert at proper place
}
}
}
