Merge Sort in C++ not behaving as expected [closed]
Closed just now.
Hey… Below is a code in C++ that implements merge sort. I tried several times but could not trace the mistake that I am making
I have been trying to remove the error in this code from last few days now. I have done everything that I possibly could have. Please help!!!. Basically this code uses vectors of C++ stl and passes the vector in a method called mergeSort which recurrsively calls itself over two parts of the vector and then calls another function which merges these parts and stores the value in a temporary vector called Temp. In the end this function copies the temp vector back into the old vector. And main does the rest.
Mergesort algorithm using c++
void merge(int *arr, int lo, int mid, int hi) { int* temp = new int[hi – lo + 1]; int i = lo; int j = mid + 1; int k = 0; while (i <= mid && j <= hi) { if (arr[i] <= arr[j]) { temp[k++] = arr[i++]; } else { temp[k++] = […]