/*
* @brief selection sort
*/
void
selection_sort(int a[], int n)
{
int i, j, min, tmp;
for (i = 0; i < n - 1; ++i) {
min = i;
for (j = i+1; j < n; ++j) {
if (a[j] < a[min]) {
min = j;
}
}
if (min != i) {
tmp = a[min];
a[min] = a[i];
a[i] = tmp;
}
}
}
/* @brief insetion sort
* insert the new element to the sorted subarray
*/
void
insertion_sort(int a[], int n)
{
int i, j, num;
for (i = 1; i < n; ++i) {
num = a[i];
for (j = i - 1; j >= 0 && a[j] > num; --j)
a[j+1] = a[j];
a[j+1] = num;
}
}
/* @brief bubble sort
* move the smallest element to the front in every single loop
*/
void
bubble_sort(int a[], int n)
{
int i, j, tmp;
for (i = 0; i < n; ++i) {
for (j = n - 1; j > i; --j) {
if (a[j] < a[j-1]) {
tmp = a[j];
a[j] = a[j-1];
a[j-1] = tmp;
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有