You are viewing a single comment's thread. Return to all comments →
void merge_sort(vector<int> &arr, int left, int right, int middle){ int i=left,j=middle+1,temp_i=0; int temp[right-left+1]; while(i<=middle && j<=right){ if(arr[i]<arr[j]) temp[temp_i++]=arr[i++]; else temp[temp_i++]=arr[j++]; } while(i<=middle) temp[temp_i++]=arr[i++]; while(j<=right) temp[temp_i++]=arr[j++]; temp_i=0; for(i=left;i<=right;i++){ arr[i]=temp[temp_i++]; } } void merge(vector<int> &arr, int left, int right){ if(left<right){ int middle = (right+left)/2; merge(arr, left, middle); merge(arr, middle+1, right); merge_sort(arr,left,right,middle); } } vector<int> countingSort(vector<int> arr) { merge(arr,0,arr.size()-1); return arr; }
Merge sort ver, believe it's quick.
Counting Sort 2
You are viewing a single comment's thread. Return to all comments →
Merge sort ver, believe it's quick.