归并排序(递归)
void MergeSort(int *A, int n){
if(n == 1){
return ;
}
int *C = new int[n];
int l1 = n/2;
int l2 = n-l1;
MergeSort(A, l1);
MergeSort(&A[l1], l2);
for(int i = 0, j = l1, k = 0; k < n;){
while(i!=l1 && j != n){
if(A[i]<A[j]){
C[k] = A[i];
k++;
i++;
}else{
C[k] = A[j];
j++;
k++;
}
}
if(i == l1){
C[k] = A[j];
j++;
k++;
}else if(j == n){
C[k] = A[i];
i++;
k++;
}
}
memcpy(A, C, sizeof(int)*n);
delete[] C;
return ;
}