九种排序算法——归并排序(稳定)
#include<iostream>
#include <cstring>
using namespace std;
void handle(int A[],int low,int mid,int high){
int *B=new int[12];
int i,j,k;
for(k=low;k<=high;k++){
B[k]=A[k];
}
for(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++];
}
void Sort(int A[],int low,int high){
if(low<high){
int mid=(low+high)/2;
Sort(A,low,mid);
Sort(A,mid+1,high);
handle(A,low,mid,high);
}
}
int main()
{
int a[]={0,15,36,11,8,25,35,19,99,107,14,92};
Sort(a,0,11);
for(int k=0;k<12;k++){
cout<< a[k]<<" ";
}
cout<<endl;
}