mooc笔记
老师:唐大仕
#include<iostream>
using namespace std;
int a[10]={10,11,2,34,55,98,7,6,21,0};
int b[10];
void Merge(int sort[],int s,int m,int e,int temp[]){
int p1=s;
int p2=m+1;
int p3=0;
while(p1<=m && p2<=e){
if(sort[p1]<sort[p2]){
temp[p3++]=sort[p1++];
}else{
temp[p3++]=sort[p2++];
}
}
while(p1<=m){
temp[p3++]=sort[p1++];
}
while(p2<=e){
temp[p3++]=sort[p2++];
}
for(int i=0;i<e-s+1;++i){
a[s+i]=temp[i];
}
}
void MergeSort(int sort[],int s,int e,int temp[]){
if(s<e){
int m=s+(e-s)/2;
MergeSort(sort,s,m,temp);
MergeSort(sort,m+1,e,temp);
Merge(sort,s,m,e,temp);
}
}
int main(){
for(int i=0;i<10;++i){
cout<<a[i]<<" ";
}
cout<<endl;
MergeSort(a,0,9,b);
for(int i=0;i<10;++i){
cout<<b[i]<<" ";
}
cout<<endl;
return 0;
}