From 3bb67e52b6a2dc468c7ba17930b9376d0f252802 Mon Sep 17 00:00:00 2001 From: Aanya Kumari <101557638+Aanya9693@users.noreply.github.com> Date: Tue, 11 Oct 2022 22:21:07 +0530 Subject: [PATCH] Merge_Sort_Algorithm.cpp I have used recursion and array to solve this problem. --- .../Sorting_Algorithms/Merge_Sort.cpp | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 important-Algorithms/Sorting_Algorithms/Merge_Sort.cpp diff --git a/important-Algorithms/Sorting_Algorithms/Merge_Sort.cpp b/important-Algorithms/Sorting_Algorithms/Merge_Sort.cpp new file mode 100644 index 0000000..ecc1999 --- /dev/null +++ b/important-Algorithms/Sorting_Algorithms/Merge_Sort.cpp @@ -0,0 +1,76 @@ +#include +using namespace std; + +void swapping(int &a, int &b) { //swap the content of a and b + int temp; + temp = a; + a = b; + b = temp; +} + +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; //create an array with given number of elements + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); //0 for first index and (n-1) for last index + cout << "Array after Sorting: "; + display(arr, n); +}