二路归并排序
void mergeSort(int data[],int temp[],int a,int b) { if(a<b) { int mid=(a+b)/2; mergeSort(data,temp,a,mid); mergeSort(data,temp,mid+1,b); merge(data,temp,a,mid,b); } } void merge(int data[],int temp[],int low,int mid,int high) { int i=low,j=mid+1,k=low; while(i<=mid&&j<=high){ if(data[i]<=data[j]) // 小于表示从小到大排序 temp[k++]=data[i++]; else temp[k++]=data[j++]; } while(i<=mid) temp[k++]=data[i++]; while(j<=high) temp[k++]=data[j++]; for(i=low;i<=high;i++)// 写回原数组 data[i]=temp[i]; }