/*-------------------------- typedef.h 方便修改待排序元素类型 -------------------------------------*/ #ifndef TYPEDEF_H #define TYPEDEF_H typedef int T; #endif
/*---------------------------------------------------------------------------------------
Insertion_sort.h
直接插入排序
对以数组形式给出的元素排序
时间复杂度为(逆序数)N(N-1)/4 = O(N^2),并且在最坏情形下达到这个值
最好情形下运行N次,最坏情形下运行2+3+…+N
------------------------------------------------------------------------------------------------*/
#ifndef INSERTION_SORT_H
#define INSERTION_SORT_H
#include "typedef.h"
//直接插入排序
void Insertion_sort(T *a, int n)
{
for(int i = 1; i != n; ++i)
{
T temp = a[i];
int j = i - 1;
for(; j >= 0 && temp < a[j]; --j )
a[j + 1] = a[j];
a[j + 1] = temp;
}
}
#endif
/*----------------------------------------------
DirectSelection_sort.h
直接选择排序
时间复杂度O(N^2)
--------------------------------------------------------*/
#ifndef DIRECTSELECTION_SORT_H
#define DIRECTSELECTION_SORT_H
#include "typedef.h"
#include "swap.h"
//直接选择法排序
void DirectSelection_sort(T*a, int n)
{
for(int i = 0; i != n; ++i)
{
int k = i;
for(int j = i; j != n; ++j)
if(a[j] < a[k]) k = j;
swap(a[k],a[i]);
}
}
#endif
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有