修改排序算法代码

This commit is contained in:
huihut
2018-04-16 13:38:05 +08:00
parent fd5ba9d077
commit 91d24f13d0
6 changed files with 11 additions and 3 deletions

View File

@ -5,6 +5,8 @@ using namespace std;
/*****************
桶排序将值为i的元素放入i号桶最后依次把桶里的元素倒出来。
桶排序序思路:
1. 设置一个定量的数组当作空桶子。
2. 寻访序列,并且把项目一个一个放到对应的桶子去。

View File

@ -1,5 +1,7 @@
/*****************
计数排序统计小于等于该元素值的元素的个数i于是该元素就放在目标数组的索引i位i≥0
计数排序基于一个假设待排序数列的所有数均出现在0k的区间之内如果k过大则会引起较大的空间复杂度
计数排序并非是一种基于比较的排序方法,它直接统计出键值本应该出现的位置
时间复杂度为On空间复杂度为On+k

View File

@ -2,6 +2,8 @@
#include <algorithm>
using namespace std;
// 堆排序:(最大堆,有序区)。从堆顶把根卸出来放在有序区之前,再恢复堆。
void max_heapify(int arr[], int start, int end) {
//建立父節點指標和子節點指標
int dad = start;

View File

@ -1,3 +1,6 @@
// 归并排序:把数据分为两段,从两段中逐个选最小的元素移入新数据段的末尾。可从上到下或从下到上进行。
/*****************
迭代版
*****************/

View File

@ -1,6 +1,4 @@
/*****************
基数排序
*****************/
// 基数排序:一种多关键字的排序算法,可用桶排序实现。
int maxbit(int data[], int n) //辅助函数,求数据的最大位数
{

View File

@ -1,3 +1,4 @@
// 希尔排序每一轮按照事先决定的间隔进行插入排序间隔会依次缩小最后一次一定要是1。
template<typename T>
void shell_sort(T array[], int length) {
int h = 1;