33void merge(
int *arr,
int l,
int m,
int r) {
38 int *L =
new int[n1], *R =
new int[n2];
40 for (i = 0; i < n1; i++) L[i] = arr[l + i];
41 for (j = 0; j < n2; j++) R[j] = arr[m + 1 + j];
46 while (i < n1 || j < n2) {
47 if (j >= n2 || (i < n1 && L[i] <= R[j])) {
73 int m = l + (r - l) / 2;
84void show(
int *arr,
int size) {
85 for (
int i = 0; i < size; i++) std::cout << arr[i] <<
" ";
92 std::cout <<
"Enter the number of elements : ";
94 int *arr =
new int[size];
95 std::cout <<
"Enter the unsorted elements : ";
96 for (
int i = 0; i < size; ++i) {
100 std::cout <<
"Sorted array : ";
void merge(int *arr, int l, int m, int r)
void mergeSort(int *arr, int l, int r)