void Merge(int* array, int* tempararay, int left, int middle, int right)
{
int leftstart = left;
int rightstart = middle-1;
int tempIndex = leftstart;
while(leftstart<rightstart)
{
if(array[leftstart]<array[rightstart])
{
tempararay[tempIndex++] = array[leftstart++];
}
else
tempararay[tempIndex++] = array[rightstart++];
}
}
void MergeSort(int* array, int* temparray, int left, int right)
{
if(left < right)
{
int middle = (left+right)/2;
MergeSort(array, temparray, left, middle);
MergeSort(array, temparray, middle+1, right);
Merge(array, temparray, left, middle+1, right);
}
}
归并排序
最新推荐文章于 2012-06-30 11:38:29 发布