经典排序算法
该源代码为排序工具类,使用模板函数实现了常见的经典排序算法:冒泡排序、插入排序、选择排序、归并排序和快速排序。算法适用于普通数据类型也可用户自定义用户对象类型,不过用户自定义类型需实现比较运算符的重载。
static void BubbleSort(T array[], unsigned size, bool toUpper)/* if is true, result such as 1 ,2 3 )*/---冒泡排序
array使用户希望排序的集合数组, size为数组的大小
参数toUpper为排序方式,若为true则从小到大,反之为从大到小
static void SelectSort(T array[], unsigned size, bool toUper)//选择排序
static void InsertSort(T array[], unsigned size, bool toUper)//插入排序
static void MergeSort(T array[], unsigned size, bool toUper)//归并排序
static void QSort(T array[], unsigned size, bool toUper)//快速排序
用户稍加修改即可应用到标准模板类集合上,这些算法是常用的算法,主要供大家学习研究使用
代码下载
浙公网安备 33010602011771号