//
void MergeSort(int sourceArr[],int tempArr[],int startIndex,int endIndex)
{
void Merge(int sourceArr[],int tempArr[],int startIndex,int midIndex, int endIndex);
int midIndex;
if(startIndex < endIndex)
{
midIndex = (startIndex + endIndex)/2;
MergeSort(sourceArr,tempArr,startIndex,midIndex);
MergeSort(sourceArr,tempArr,midIndex+1,endIndex);
Merge(sourceArr,tempArr,startIndex,midIndex,endIndex);
}
}
void Merge(int sourceArr[],int tempArr[],int startIndex,int midIndex, int endIndex)
{
int i = startIndex,j=midIndex+1,k = startIndex;
while(i != midIndex+1 && j != endIndex+1 )
{
if(sourceArr[i] > sourceArr[j])
tempArr[k++] = sourceArr[j++];
else
tempArr[k++] = sourceArr[i++];
}
while(i != midIndex+1)
tempArr[k++] = sourceArr[i++];
while(j != endIndex+1)
tempArr[k++] = sourceArr[j++];
for(i=startIndex;i<endIndex;i++)
sourceArr[i] = tempArr[i];
}
//快速排序
void quickSort(int a[],int left,int right)
{
if(left >= right)
{
return;
}
int i = left;
int j = right;
int key = a[left];
while(i<j)
{
while(i<j && key<=a[j])
{
j--;
}
a[i] = a[j];
while(i<j && key>=a[i])
{
i++;
}
a[j] = a[i];
}
a[i] = key;
quickSort(a,left,i-1);
quickSort(a,i+1,right);
}
//直接排序
void inserSort(int p[],int n)
{
int temp=0,j,i;
for(i=1;i<n;i++)
{
j = i -1;
temp=p[i];
for(;j>=0 && temp<p[j];j--)
{
p[j+1] = p[j];
}
p[j+1] = temp;
}
}
//希尔排序(最小增量)
void shellSort(int a[],int n)
{
int temp=0;
double d1 = n;
while(1)
{
d1 = ceil(d1/2);
int d = (int) d1;
int x = 0;
for(;x<d;x++)
{
int i = x + d;
for(;i<n;i+=d)
{
int j =i - d;
temp = a[i];
for(;j>=0 && temp < a[j];j-=d)
{
a[j+d] = a[j];
}
a[j+d] = temp;
}
}
if(d==1)
{
break;
}
}
}
//简单选择排序
void selectSort(int a[],int n)
{
int position=0,i,temp;
for(i = 0;i<n;i++)
{
int j=i+1;
position = i;
temp = a[i];
for(;j < n;j++)
{
if(a[j]<temp)
{
temp = a[j];
position = j;
}
}
a[position] = a[i];
a[i] = temp;
}
}
//冒泡排序
void bubbleSort(int a[],int n)
{
int temp = 0;
int i;
for(i=0;i<n;i++)
{
int j;
for(j=0;j<n-1-j;j++)
{
if(a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}