//直接插入排序
void InsertSort(int arry[], int n)
{
int i, j;
int temp;//临时变量
for (i = 1; i < n; i++)
{
temp = arry[i];
for (j = i - 1; j >= 0; j--)
{
if (temp > arry[j])
break;
else
arry[j + 1] = arry[j];
}
arry[j+1] = temp;
}
}
//直接选择排序
void SelectSort(int arry[], int n)
{
int i, j;
int temp;
for (i = 0; i < n-1; i++)
{
temp = i;
for (j = i + 1; j < n; j++)
{
if (arry[j] < arry[temp])
temp = j;
}
if(temp!=i)
arry[temp] ^= arry[i] ^= arry[temp] ^= arry[i];//实现arry[temp]和arry[i]值交换
}
}
//冒泡排序
void BubbleSort(int arry[], int n)
{
int i, j, k;
for (i = 0; i < n-1; i++)
{
for (j = i; j < n; j++)
{
if (arry[j - 1]>arry[j])
arry[j - 1] ^= arry[j] ^= arry[j - 1] ^= arry[j];//实现arry[temp]和arry[i]值交换
}
}
}
//希尔排序第一类,
void ShellSort1(int arry[], int n)
{
int i, j, k, gap,temp;
for (gap = n / 2; gap > 0; gap /= 2)
{
for (k = 0; k < gap; k++)//同组先排
{
for (i = k+gap; i < n; i += gap)
{
temp = arry[i];
for (j = i - gap; j >= 0; j -= gap)
{
if (temp > arry[j])
break;
else
arry[j + gap] = arry[j];
}
arry[j + gap] = temp;
}
}
}
}
//希尔排序第二类
void ShellSort2(int arry[], int n)
{
int i, j, k, gap, temp;
for (gap = n / 2; gap > 0; gap /= 2)
{
for (i = gap; i < n; i++)//所有组一起排序
{
temp = arry[i];
for (j = i - gap; j >= 0; j -= gap)
{
if (temp > arry[j])
break;
else
arry[j + gap] = arry[j];
}
arry[j + gap] = temp;
}
}
}
//希尔排序,利用gap分组后采用冒泡方式排序
void ShellSort3(int arry[], int n)
{
int i, j, k, gap, temp;
for (gap = n / 2; gap > 0; gap /= 2)
{
for (k = 0; k < gap; k++)
{
for (i = k; i < n-gap; i += gap)
{
for (j = k+gap; j <n ; j += gap)
{
if (arry[j - gap]>arry[j])
arry[j - gap] ^= arry[j] ^= arry[j - gap] ^= arry[j];
}
}
}
}
}
//快速排序,递归调用
void QuickSort(int arry[], int s,int t)
{
int i, j;
if (s < t)
{
i = s;
j = t+1;
while (1)
{
do
{
i++;
}while (!(arry[s] <= arry[i] || i >= t));
do
{
j--;
} while (!(arry[s] >= arry[j] || j <= s));
if (i < j)
arry[i] ^= arry[j] ^= arry[i] ^= arry[j];