From 539dccf70d52fb165c06f179a516358fffb03133 Mon Sep 17 00:00:00 2001 From: Ishika <96570918+Ishika0-0@users.noreply.github.com> Date: Tue, 17 Oct 2023 17:01:28 +0530 Subject: [PATCH] Create Mergesort.cpp Added merge sort algorithm in c++ folder --- C++/Mergesort.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 C++/Mergesort.cpp diff --git a/C++/Mergesort.cpp b/C++/Mergesort.cpp new file mode 100644 index 0000000..8c011d6 --- /dev/null +++ b/C++/Mergesort.cpp @@ -0,0 +1,66 @@ +#include +using namespace std; +void swapping(int &a, int &b) { + int temp; + temp = a; + a = b; + b = temp; +} +void display(int *array, int size) { + for(int i = 0; i> n; + int arr[n]; + cout << "Enter elements:" << endl; + for(int i = 0; i> arr[i]; + } + cout << "Array before Sorting: "; + display(arr, n); + mergeSort(arr, 0, n-1); + cout << "Array after Sorting: "; + display(arr, n); +}