Daa 3
Daa 3
Daa 3
Aim - : Write a program to sort a array by using merge and quick sort in c language.
Quick Sort
#include <stdio.h>
#include <stdio.h>
*a = *b;
*b = temp;
// Partition function
swap(&arr[i], &arr[j]);
return (i + 1);
// QuickSort function
quickSort(arr, pi + 1, high);
printf("\n");
int main() {
quickSort(arr, 0, n - 1);
printArray(arr, n);
return 0;
}
Merge sort :
#include <stdio.h>
int i, j, k;
int n1 = m - l + 1;
int n2 = r - m;
arr[k] = L[i];
i++;
} else {
arr[k] = R[j];
j++;
k++;
}
// Copy the remaining elements of L[], if any
arr[k] = L[i];
i++;
k++;
arr[k] = R[j];
j++;
k++;
// MergeSort function
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
printf("\n");
}
int main() {
printArray(arr, arr_size);
printArray(arr, arr_size);
return 0;