两个O(nlogn)的排序方法
QSort(快排):
int Partition(int *R,int low,int high)
{
int pivotkey=R[low];
while(low=pivotkey)
high--;
R[low]=R[high];
while(low
MSort(归并):
void Merge(int *R,int *RL,int first,int m,int last)//R为原数组 RL为中间数组
{
int i,k;
int begin1=first;
int end1=m;
int begin2=m+1;
int end2=last;
for(k=first;begin1<=end1&&begin2<=end2;k++)
{
if(R[begin1]<=R[begin2]) RL[k]=R[begin1++];
else RL[k]=R[begin2++];
}
while(begin1<=end1)
{
RL[k++]=R[begin1++];
}
while(begin2<=end2)
{
RL[k++]=R[begin2++];
}
for(i=first;i<=last;i++)
{
R[i]=RL[i];
}
}
void MSort(int *R,int *RL,int first,int last)
{
if(first
