void MergeArray(int cry[],int temp[],int begin,int middle,int end) { int i=begin; int j=middle+1; int k=i; while(i<=middle&&j<=end) { if(cry[i]<=cry[j]) { temp[k]=cry[i]; i++; } else { std::cout<<"["<<i<<","<<j<<"]:"<<cry[i]<<" "<<cry[j]<<endl; temp[k]=cry[j]; j++; } k++; } while(i<=middle) { temp[k]=cry[i]; i++; k++; } while(j<=end) { temp[k]=cry[j]; k++; j++; } for(int m=begin;m<=end;++m) cry[m]=temp[m]; } void Merge(int cry[],int temp[] ,int begin,int end) { if(begin<end) { int middle=(begin+end)/2; Merge(cry,temp,begin,middle); Merge(cry,temp,middle+1,end); MergeArray(cry,temp,begin,middle,end); } } void MergeSort(int cry[],int N) { int* temp=new int[N](); Merge(cry,temp,0,N-1); delete[]temp; }