1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| void merge_sort(int a[] , int l ,int r){ if (l == r) return ; int mid = l + r >> 1; merge_sort(a,l,mid); merge_sort(a,mid + 1, r); int k = 0 , i = l , j = mid + 1; while (i <= mid && j <= r){ if (a[i] <= a[j]) t[k++] = a[i++]; else t[k++] = a[j++]; } while (i <= mid) t[k++] = a[i++]; while (j <= r) t[k++] = a[j++]; for(int i = 0, j = l; j <= r ; j++, i ++) a[j] = t[i]; }
|