void Merge_sort(long Left,long Right) { long Middle; if(Left<Right) { Middle=(Left+Right) >> 1; Merge_sort(Left,Middle); // 二分分解左部分 Merge_sort(Middle+1,Right); // 二分分解有部分 Merge(Left,Middle,Right); //合并两部分 }
static void Merge_sort(int *array, int begin, int end, int *temp) { int mid = 0; if(end > begin){ //还可进行拆分 // mid = (begin + end ) / 2; mid = begin + (end - begin >> 1); Merge_sort(array, begin, mid, temp); Merge_sort(array, mid + 1, end, temp); merge_array(array, begin, mid, end, temp); }
int main(){ int a[100]; for(int i=0; i<100; i++) scanf("%d",&a[i]); int b[100]; Merge_sort(a,b,100); }