Skip to content

Commit fd5ba9d

Browse files
committed
把排序算法的描述放到代码中,让README简洁点
1 parent 3a00798 commit fd5ba9d

5 files changed

Lines changed: 20 additions & 12 deletions

File tree

Algorithm/BubbleSort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
3+
(无序区,有序区)。从无序区通过交换找出最大元素放到有序区前端。
4+
35
选择排序思路:
46
1. 比较相邻的元素。如果第一个比第二个大,就交换他们两个。
57
2. 对每一对相邻元素作同样的工作,从开始第一对到结尾的最后一对。这步做完后,最后的元素会是最大的数。

Algorithm/InsertSort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
3+
(有序区,无序区)。把无序区的第一个元素插入到有序区的合适的位置。对数组:比较得少,换得多。
4+
35
插入排序思路:
46
1. 从第一个元素开始,该元素可以认为已经被排序
57
2. 取出下一个元素,在已经排序的元素序列中从后向前扫描

Algorithm/QuickSort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
3+
(小数,基准元素,大数)。在区间中随机挑选一个元素作基准,将小于基准的元素放在基准之前,大于基准的元素放在基准之后,再分别对小数区与大数区进行排序。
4+
35
快速排序思路:
46
1. 选取第一个数为基准
57
2. 将比基准小的数交换到前面,比基准大的数交换到后面

Algorithm/SelectionSort.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*
22
3+
(有序区,无序区)。在无序区里找一个最小的元素跟在有序区的后面。对数组:比较得多,换得少。
4+
35
选择排序思路:
46
1. 在未排序序列中找到最小(大)元素,存放到排序序列的起始位置
57
2. 从剩余未排序元素中继续寻找最小(大)元素,然后放到已排序序列的末尾

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,18 +1245,18 @@ typedef struct BiTNode
12451245

12461246
### 排序
12471247

1248-
排序算法 | 平均时间复杂度 | 最差时间复杂度 | 空间复杂度 | 数据对象稳定性 | 描述
1249-
---|---|---|---|---|---
1250-
[冒泡排序](Algorithm/BubbleSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|稳定|(无序区,有序区)。从无序区通过交换找出最大元素放到有序区前端。
1251-
[选择排序](Algorithm/SelectionSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|数组不稳定、链表稳定|(有序区,无序区)。在无序区里找一个最小的元素跟在有序区的后面。对数组:比较得多,换得少。
1252-
[插入排序](Algorithm/InsertSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|稳定|(有序区,无序区)。把无序区的第一个元素插入到有序区的合适的位置。对数组:比较得少,换得多。
1253-
[快速排序](Algorithm/QuickSort.h) | O(n*log<sub>2</sub>n) | O(n<sup>2</sup>) | O(log<sub>2</sub>n) | 不稳定|(小数,基准元素,大数)。在区间中随机挑选一个元素作基准,将小于基准的元素放在基准之前,大于基准的元素放在基准之后,再分别对小数区与大数区进行排序。
1254-
[堆排序](Algorithm/HeapSort.h) | O(n*log<sub>2</sub>n)|O(n<sup>2</sup>)|O(1)|不稳定|(最大堆,有序区)。从堆顶把根卸出来放在有序区之前,再恢复堆。
1255-
[归并排序](Algorithm/MergeSort.h) | O(n*log<sub>2</sub>n) | O(n*log<sub>2</sub>n)|O(1)|稳定|把数据分为两段,从两段中逐个选最小的元素移入新数据段的末尾。可从上到下或从下到上进行。
1256-
[希尔排序](Algorithm/ShellSort.h) | O(n*log<sup>2</sup>n)|O(n<sup>2</sup>)|O(1)|不稳定|每一轮按照事先决定的间隔进行插入排序,间隔会依次缩小,最后一次一定要是1。
1257-
[计数排序](Algorithm/CountSort.h) | O(n+m)|O(n+m)|O(n+m)|稳定|统计小于等于该元素值的元素的个数i,于是该元素就放在目标数组的索引i位(i≥0)。
1258-
[桶排序](Algorithm/BucketSort.h) | O(n)|O(n)|O(m)|稳定|将值为i的元素放入i号桶,最后依次把桶里的元素倒出来。
1259-
[基数排序](Algorithm/RadixSort.h) | O(k*n)|O(n<sup>2</sup>)| |稳定|一种多关键字的排序算法,可用桶排序实现。
1248+
排序算法 | 平均时间复杂度 | 最差时间复杂度 | 空间复杂度 | 数据对象稳定性
1249+
---|---|---|---|---
1250+
[冒泡排序](Algorithm/BubbleSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|稳定
1251+
[选择排序](Algorithm/SelectionSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|数组不稳定、链表稳定
1252+
[插入排序](Algorithm/InsertSort.h) | O(n<sup>2</sup>)|O(n<sup>2</sup>)|O(1)|稳定
1253+
[快速排序](Algorithm/QuickSort.h) | O(n*log<sub>2</sub>n) | O(n<sup>2</sup>) | O(log<sub>2</sub>n) | 不稳定
1254+
[堆排序](Algorithm/HeapSort.h) | O(n*log<sub>2</sub>n)|O(n<sup>2</sup>)|O(1)|不稳定
1255+
[归并排序](Algorithm/MergeSort.h) | O(n*log<sub>2</sub>n) | O(n*log<sub>2</sub>n)|O(1)|稳定
1256+
[希尔排序](Algorithm/ShellSort.h) | O(n*log<sup>2</sup>n)|O(n<sup>2</sup>)|O(1)|不稳定
1257+
[计数排序](Algorithm/CountSort.h) | O(n+m)|O(n+m)|O(n+m)|稳定
1258+
[桶排序](Algorithm/BucketSort.h) | O(n)|O(n)|O(m)|稳定
1259+
[基数排序](Algorithm/RadixSort.h) | O(k*n)|O(n<sup>2</sup>)| |稳定
12601260
[文件排序](Algorithm/FileSort) |
12611261

12621262
> * 均按从小到大排列

0 commit comments

Comments
 (0)