1、直接插入排序
void InsertSort(int array[], int size)
{
for(int idx=1; idx<size; idx++)
{
int temp = array[idx];
int end = idx-1;
while(end>=0 && array[end] > temp)
{
array[end+1] = array[end];
--end;
}
array[end+1] = temp;
}
}
2、希尔排序
void ShellSort(int array[], int size)
{
int gap = size;
while(gap > 1)
{
gap = gap/3 + 1;
for(int idx = gap; idx < size; ++idx)
{
int temp = array[idx];
int end = idx - gap;
while( end >= 0 && temp < array[end])
{
array[end+gap] = array[end];
end -= gap;
}
array[end + gap] = temp;
}
}
}