摘要:#include <stdio.h>
#include <stdlib.h>
void MergeSort(int a[],int temp[],int low,int high)
{
int middle ;
if (low<hig
#include <stdio.h>
#include <stdlib.h>
void MergeSort(int a[],int temp[],int low,int high)
{
int middle ;
if (low<high)
{
middle=(low+high)/2;
MergeSort(a,temp,low,middle);
MergeSort(a,temp,middle+1,high);
Merge(a,temp,low,middle,high); //ºÏ²¢ÅÅÐò
}
}
void Merge(int a[],int temp[],int starIndex,int midIndex,int endIndex)
{
int i=starIndex,j=midIndex+1,k=starIndex;
while (i!=midIndex+1 && j!=endIndex+1)
{
if (a[i]>a[j])
{
temp [k++]=a[i++];
}
else
{
temp [k++]=a[j++];
}
}
while (i!=midIndex+1)
temp =[k++]=a[i++];
while (j!=endIndex+1)
temp [k++]=a[j++];
for (i=starIndex;i<endIndex;++i)
{
a[i]=temp [i];
}
}