#include <stdio.h>
void merge(int a[],int temp[],int L,int R,int RightEnd);
void merge(int a[],int tempArray[],int L,int R,int RightEnd){
int i,temp,LeftEnd,NumElemments;
LeftEnd = R - 1;
temp = L;
NumElemments = RightEnd - L + 1;
while(L <= LeftEnd && R <= RightEnd){
if(a[L] >= a[R]){
tempArray[temp] = a[R];
R++;
temp++;
}else{
tempArray[temp] = a[L];
L++;
temp++;
}
}
while(L <= LeftEnd){
tempArray[temp++] = a[L++];
}
while(R <= RightEnd){
tempArray[temp++] = a[R++];
}
for(i = 0;i < NumElemments;i++,RightEnd--){
a[RightEnd] = tempArray[RightEnd];
}
for(i = 0;i < NumElemments;i++){
printf("%d ",a[i]);
}
}
int main () {
int a[6] = {34,51,89,16,20,25};
int tempArray[6];
printf("排序前的元素为:\n");
for(int i = 0;i < 6;i++){
printf("%d ",a[i]);
}
printf("\n");
printf("排序后的元素为:\n");
merge(a,tempArray,0,3,5);
}