quicksort and merge sort
quicksort and merge sort
1. Quick Sort and Merge Sort: The program defines both Quick Sort and Merge Sort algorithms.
2. Input Cases:
3. Time Measurement: The clock() function measures the time taken by each sorting algorithm
for the given input size and case.
4. Sizes: The array sizes are defined in the sizes[] array. You can modify these as needed.
Program:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int t = *a;
*a = *b;
*b = t;
i++;
swap(&arr[i], &arr[j]);
quickSort(arr, pi + 1, high);
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
i = 0;
j = 0;
k = l;
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
}
k++;
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
if (caseType == 'b') {
} else {
void measureSortTime(int arr[], int size, void (*sortFunc)(int[], int, int), char* sortName, char
caseType) {
double cpu_time_used;
start = clock();
end = clock();
printf("%s Sort (Size %d, Case '%c'): %f seconds\n", sortName, size, caseType, cpu_time_used);
int main() {
srand(time(0));
int sizes[] = {1000, 5000, 10000, 50000, 100000}; // Different array sizes
free(arr);
printf("\n");
return 0;