From 3aeb1fceff91885803c8cffe985c61c6a10adcb8 Mon Sep 17 00:00:00 2001 From: SAM <73647831+samhackathon@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:30:21 +0500 Subject: [PATCH] Delete merge sort.cpp --- merge sort.cpp | 72 -------------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 merge sort.cpp diff --git a/merge sort.cpp b/merge sort.cpp deleted file mode 100644 index 00837797344..00000000000 --- a/merge sort.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#include - -using namespace std; - -void merge(int arr[], int p, int q, int r) { - - int n1 = q - p + 1; - int n2 = r - q; - - int L[n1], M[n2]; - - for (int i = 0; i < n1; i++) - L[i] = arr[p + i]; - for (int j = 0; j < n2; j++) - M[j] = arr[q + 1 + j]; - - int i, j, k; - i = 0; - j = 0; - k = p; - - while (i < n1 && j < n2) { - if (L[i] <= M[j]) { - arr[k] = L[i]; - i++; - } else { - arr[k] = M[j]; - j++; - } - k++; - } - - while (i < n1) { - arr[k] = L[i]; - i++; - k++; - } - - while (j < n2) { - arr[k] = M[j]; - j++; - k++; - } -} - -void mergeSort(int arr[], int l, int r) { - if (l < r) { - int m = l + (r - l) / 2; - - mergeSort(arr, l, m); - mergeSort(arr, m + 1, r); - - merge(arr, l, m, r); - } -} - -void printArray(int arr[], int size) { - for (int i = 0; i < size; i++) - cout << arr[i] << " "; - cout << endl; -} - -int main() { - int arr[] = {6, 5, 12, 10, 9, 1}; - int size = sizeof(arr) / sizeof(arr[0]); - - mergeSort(arr, 0, size - 1); - - cout << "Sorted array: \n"; - printArray(arr, size); - return 0; -}