# Trying Implement Merge Sort Algorthim Using C Delete Statment Code Break Even Though Try D Q10664431

I am trying to implement merge sort algorthim by using c++

When I do the delete statment the code BREAK even though when Itry delete[] or delete

any help?

void merge(int array[], int p, int q, int r) { int n1 = q – p + 1; int n2 = r – q; int *left = new int[n1 + 1]; int *right = new int[n2 + 1]; for(int i = 0; i < n1; i++) left[i] = array[p + i]; for(int j = 0; j < n2; j++) right[j] = array[q + j+1]; left[n1+1] = INT_MAX; right[n2+1] = INT_MAX; int i = 0, j = 0; for(int k = 0; k < r; ++k) { if(left[i] <= right[j]) { array[k] = left[i]; i++; } else if(right[j] < left[i]) { array[k] = right[j]; j++; } } delete left; left =0; delete right; right =0;}void mergesort(int array[], int p, int r) { if(p < r) { int q = (p + r) / 2; mergesort(array, p, q – 1); mergesort(array, q, r); merge(array, p, q, r); }}

"We Offer Paper Writing Services on all Disciplines, Make an Order Now and we will be Glad to Help"
0 replies