From 2ab4820b2ecef4c2d9712227ad9482d9668d5835 Mon Sep 17 00:00:00 2001 From: 24OI-bot <15963390+24OI-bot@users.noreply.github.com> Date: Sat, 24 Aug 2019 02:53:10 -0400 Subject: [PATCH] style: format markdown files with remark-lint --- docs/basic/bubble-sort.md | 26 ++++++++++++-------------- docs/basic/insertion-sort.md | 26 ++++++++++++-------------- docs/basic/selection-sort.md | 28 ++++++++++++---------------- docs/basic/sort-intro.md | 2 +- 4 files changed, 37 insertions(+), 45 deletions(-) diff --git a/docs/basic/bubble-sort.md b/docs/basic/bubble-sort.md index 84bb7b80..56cbea77 100644 --- a/docs/basic/bubble-sort.md +++ b/docs/basic/bubble-sort.md @@ -27,19 +27,17 @@ C++ 代码: ```cpp void bubble_sort(int *a, int n) { - flag = true; - while (flag) - { - flag = false; - for (int i = 1; i < n; ++i) - { - if (a[i] > a[i + 1]) { - flag = true; - int t = a[i]; - a[i] = a[i + 1]; - a[i + 1] = t; - } - } + flag = true; + while (flag) { + flag = false; + for (int i = 1; i < n; ++i) { + if (a[i] > a[i + 1]) { + flag = true; + int t = a[i]; + a[i] = a[i + 1]; + a[i + 1] = t; + } } + } } -``` \ No newline at end of file +``` diff --git a/docs/basic/insertion-sort.md b/docs/basic/insertion-sort.md index efee4287..d1c27d30 100644 --- a/docs/basic/insertion-sort.md +++ b/docs/basic/insertion-sort.md @@ -1,10 +1,11 @@ 插入排序将数列划分为“已排序的”和“未排序的”两部分,每次从“未排序的”元素中选择一个插入到“已排序的”元素中的正确位置。 -插入排序的最坏情况时间复杂度和平均情况时间复杂度都为 $O(n^2)$,但其在数列几乎有序时效率很高。 +插入排序的最坏情况时间复杂度和平均情况时间复杂度都为 $O(n^2)$ ,但其在数列几乎有序时效率很高。 插入排序是一个稳定排序。 伪代码: + $$ \begin{array}{ll} 1 & \textbf{Input. } \text{An array } A \text{ consisting of }n\text{ elements.} \\ @@ -23,18 +24,15 @@ $$ C++ 代码: ```cpp -void insertion_sort(int* a, int n) -{ - for (int i = 2; i <= n; ++i) - { - int key = a[i]; - int j = i - 1; - while (j > 0 && a[j] > key) - { - a[j + 1] = a[j]; - --j; - } - a[j + 1] = key; +void insertion_sort(int* a, int n) { + for (int i = 2; i <= n; ++i) { + int key = a[i]; + int j = i - 1; + while (j > 0 && a[j] > key) { + a[j + 1] = a[j]; + --j; } + a[j + 1] = key; + } } -``` \ No newline at end of file +``` diff --git a/docs/basic/selection-sort.md b/docs/basic/selection-sort.md index 2a369e2f..883ae599 100644 --- a/docs/basic/selection-sort.md +++ b/docs/basic/selection-sort.md @@ -23,21 +23,17 @@ $$ C++ 代码: ```cpp -void selection_sort(int* a, int n) -{ - for (int i = 1; i < n; ++i) - { - int ith = i; - for (int j = i + 1; j <= n; ++j) - { - if (a[j] < a[ith]) - { - ith = j; - } - } - int t = a[i]; - a[i] = a[ith]; - a[ith] = t; +void selection_sort(int* a, int n) { + for (int i = 1; i < n; ++i) { + int ith = i; + for (int j = i + 1; j <= n; ++j) { + if (a[j] < a[ith]) { + ith = j; + } } + int t = a[i]; + a[i] = a[ith]; + a[ith] = t; + } } -``` \ No newline at end of file +``` diff --git a/docs/basic/sort-intro.md b/docs/basic/sort-intro.md index 60c2866d..e078dbde 100644 --- a/docs/basic/sort-intro.md +++ b/docs/basic/sort-intro.md @@ -18,6 +18,6 @@ 基于比较的排序算法的时间复杂度下限是 $O(n\log n)$ 的。 -当然也有不是 $O(n\log n)$ 的,计数排序的时间复杂度是 $O(n+w)$,其中 $w$ 代表输入数据的值域大小 。 +当然也有不是 $O(n\log n)$ 的,计数排序的时间复杂度是 $O(n+w)$ ,其中 $w$ 代表输入数据的值域大小。 当待排序的关键码序列基本有序时,插入排序最快。 -- 2.11.0