Skip to content

Commit 46930be

Browse files
committed
feat: update sorting description content
1 parent e454ea3 commit 46930be

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@
6868
"ratio": "cpp",
6969
"system_error": "cpp",
7070
"utility": "cpp",
71-
"map": "cpp"
71+
"map": "cpp",
72+
"__tree": "cpp"
7273
},
7374
"C_Cpp.errorSquiggles": "Disabled",
7475
"fileheader.LastModifiedBy": "Chacha",

basic_data_structure/heap/heap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using namespace std;
2525
int main()
2626
{
2727
// 初始化小顶堆
28-
priority_queue<int, vector<int>, greater<int> > heap;
28+
priority_queue<int, vector<int>, greater<int>> heap;
2929

3030
// 元素入堆
3131
heap.push(1);

basic_sorting/bubble_sort.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
* @Author: Chacha
33
* @Date: 2018-12-13 22:10:30
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2018-12-20 22:01:21
5+
* @Last Modified time: 2021-03-09 11:35:15
66
*/
77

88
/**
99
* Bubble Sorting
1010
* Source: https://zh.wikipedia.org/wiki/冒泡排序
11+
*
12+
* Time Complexity: O(n^2)
13+
* Space Complexity: O(n^2)
14+
*
15+
* 核心:冒泡,持续比较相邻元素,大的挪到后面,因此大的会逐步往后挪,故称之为冒泡。
1116
*/
1217

1318
#include <iostream>

basic_sorting/insertion_sort.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: Chacha
33
* @Date: 2018-12-20 22:10:30
44
* @Last Modified by: Chacha
5-
* @Last Modified time: 2018-12-27 22:03:09
5+
* @Last Modified time: 2021-03-09 11:17:34
66
*/
77

88
#include <iostream>
@@ -11,8 +11,23 @@ using namespace std;
1111
template <typename T> //整数或浮点数皆可使用,若要使用类(class)或结构体(struct)时必须重载大于(>)运算符
1212

1313
/**
14-
* Insertion Sorting
14+
* Insertion Sorting(插入排序)
1515
* Source: https://zh.wikipedia.org/wiki/插入排序
16+
*
17+
* Time Complexity: O(n^2)
18+
* Space Complexity: O(1)
19+
*
20+
* 核心:通过构建有序序列,对于未排序序列,从后向前扫描(对于单向链表则只能从前往后遍历),找到相应位置并插入。
21+
* 实现上通常使用in-place排序(需用到O(1)的额外空间)。
22+
*
23+
* 排序步骤:
24+
* 1. 从第一个元素开始,该元素可认为已排序
25+
* 2. 取下一个元素,对已排序数组从后往前扫描
26+
* 3. 若从排序数组中取出的元素大于新元素,则移至下一位置
27+
* 4. 重复步骤3,直至找到已排序元素小于或等于新元素的位置
28+
* 5. 插入新元素至该位置
29+
* 6. 重复2~5
30+
*
1631
*/
1732
void insertionSort(T arr[], int len)
1833
{
@@ -32,8 +47,11 @@ void insertionSort(T arr[], int len)
3247
}
3348

3449
/**
35-
* Shell Sorting
50+
* Shell Sorting(希尔排序)
3651
* Source: https://zh.wikipedia.org/wiki/希尔排序
52+
*
53+
* 核心:基于插入排序,使数组中任意间隔为h的元素都是有序的,即将全部元素分为h个区域使用插入排序。
54+
* 其实现可类似于插入排序但使用不同增量。更高效的原因是它权衡了子数组的规模和有序性。
3755
*/
3856
template <typename T>
3957
void shellSort(T arr[], int len)

basic_sorting/sorting_insertion.gif

1.19 MB
Loading

0 commit comments

Comments
 (0)