1.插入排序
void InsertionSort( int arr[], int num )
{
int temp;
int i, j;
for ( i = 1; i < num; i++ )
{
temp = arr[i];
for( j = i; j > 0 && arr[j-1] > temp; j--)
arr[j] = arr[j-1];
arr[j] = temp;
}
}
2.希尔排序
void ShellSort(int *arr, int n)
{
int temp;
int i, j, increment;
for (increment = n/2; increment > 0; increment /= 2)
{
for(i = increment; i < n; i++)
{
temp = arr[i];
for(j = i; j >= increment; j -= increment)
{
if(arr[ j - increment] > temp)
arr[j] = arr[ j - increment];
else
break;
}
arr[j] = temp;
}
}
}
3.选择排序
void SelectSort(int arr[]; int num)
{
int i, j, Mindex, temp;
for(i = 0; i < num; i++)
{
Mindex = i;
for(j = i + 1; j < num; i++)
{
if(arr[j] < arr[Mindex])
Medex = j;
}
temp = arr[i]; arr[i] = arr[Mindex]; arr[Mindex] = temp;
}
}