void MergeSort(int a[],int low,int high){
if(low<high){
int mid = (low + high)/2;
MergeSort(a,low,mid);
MergeSort(a,mid+1,high);
Merge(a,low,mid,high);
}
}
int *b = (int *)malloc(sizeof(int) * (n+1));
void Merge(int a[],int low,int mid,int high){
for(int k = low;low <= high;k++){
b[k] = a[k];
}
for(int i = low,j = mid+1,k= i;i<mid&&j<high;k++){
if(b[i]<=b[j]){
a[k] = b[i++];
}else{
a[k] = b[j++];
}
}
while(i<=mid){
a[k++] = b[i++];
}
while(j<=high){
a[k++] = b[j++];
}
}
归并排序
最新推荐文章于 2023-09-03 20:36:33 发布