一、希尔排序
1 void shellSort(int*a, int len)
2 {
3 int key = 0;
4 int gap = len/2;
5
6 while (gap>=1)
7 {
8
9 for (int i=gap;i<len;i++)
10 {
11 key = a[i];
12 int j = i;
13 while (j>=gap&&key<a[j-gap])//倒序(key>a[j-gap])
14 {
15 a[i] = a[i - gap];
16
17 j=j-gap;
18 }
19 a[j] = key;
20 }
21 gap = gap / 2;
22 }
23 }
二、冒泡排序
//冒泡排序
void BubbleSort(int *a, int len)
{
int i, j, temp;
for (j = 0; j < len - 1; j++)
{
for (i = 0; i < len - j - 1; i++)
{
if (a[i] > a[i + 1])
{
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
}
}