+ 1

Merge sort Error

#include <iostream> using namespace std; const int max = 5; int arr[max]={1,3,6,2,0}; void merge(int low, int mid, int high); void merge_sort(int arr[], int low, int high); int main() { cout<<"Before sorted: \n"; for(int i = 0 ; i < max ; i++) { cout<<arr[i]<<" "; } merge_sort (0, max -1); cout <<"Sorted array: \n"; for (int i = 0 ;i< max; i++) { cout<<arr[i]<<" "; } return 0; } void merge_sort (int arr[], int low , int high ) { int mid; if(low < high ) { mid=(low + high)/2; merge_sort(arr,low, mid); merge_sort (arr,mid+1, high ); merge (arr,mid,high ); } } void merge (int arr[], int low, int high ) { int i = low; int j =mid +1; int k = low int temp[max]; while((i<=mid)&&(j<=high)) { if(arr[i]<=arr[j]) temp[k++]=arr[i++]; else temp[k++]=arr[j++]; } while(i<=mid) temp[k++]=arr[i++]; while(j<=high) temp[k++]=arr[j++]; for(i=

29th May 2019, 4:51 PM
Issa Adam
Issa Adam - avatar
1 Answer
+ 5
Isaac_Adam04 hi, Good initiative by posting your try here is your updated code https://code.sololearn.com/c3Ti42V9rrV9/?ref=app Have these 🍎 🍎 🍎 🍎 🍎
29th May 2019, 5:50 PM
DishaAhuja
DishaAhuja - avatar