File tree Expand file tree Collapse file tree 6 files changed +70
-6
lines changed
Expand file tree Collapse file tree 6 files changed +70
-6
lines changed Original file line number Diff line number Diff line change 1- # My Awesome Book
1+ # 十大经典排序算法
22
3- This file file serves as your book's preface, a great place to describe your book's content and ideas.
3+ 排序算法是《数据结构与算法》中最基本的算法之一。用一张图概括:
4+
5+ ![ 十大经典排序算法 概览截图] ( res/sort.png )
6+
7+
8+ 名词解释:
9+
10+ ** n** :数据规模
11+
12+ ** k** :“桶”的个数
13+
14+ ** In-place** :占用常数内存,不占用额外内存
15+
16+ ** Out-place** :占用额外内存
17+
18+ ** 稳定性** :排序后2个相等键值的顺序和排序之前它们的顺序相同
19+
20+ ----
21+
22+ 为了方便大家学习排序算法,整理文章内容成 GitBook:[ https://wowphp.com/post/komxdx8qe862.html ] ( https://wowphp.com/post/komxdx8qe862.html )
23+
24+ 本项目整理人 GitHub 账号:[ hustcc] ( https://github.com/hustcc ) 。
Original file line number Diff line number Diff line change 11# Summary
22
3- * [ First Chapter] ( chapter1.md )
3+ 1 . [ 冒泡排序] ( bubbleSort.md )
4+ 2 . [ 选择排序] ( selectionSort.md )
5+ 3 . [ 插入排序] ( insertionSort.md )
6+ 4 . [ 希尔排序] ( shellSort.md )
7+ 5 . [ 归并排序] ( mergeSort.md )
8+ 6 . [ 快速排序] ( quickSort.md )
9+ 7 . [ 堆排序] ( heapSort.md )
10+ 8 . [ 计数排序] ( countingSort.md )
11+ 9 . [ 桶排序] ( bucketSort.md )
12+ 10 . [ 基数排序] ( radixSort.md )
Original file line number Diff line number Diff line change 1+ # 冒泡排序
2+
3+ 作为最简单的排序算法之一,冒泡排序给我的感觉就像 Abandon 在单词书里出现的感觉一样,每次都在第一页第一位,所以最熟悉。冒泡排序还有一种优化算法,就是立一个 flag,当在一趟序列遍历中元素没有发生交换,则证明该序列已经有序。但这种改进对于提升性能来说并没有什么太大作用。
4+
5+
6+ ## 1. 什么时候最快
7+
8+ 当输入的数据已经是正序时(都已经是正序了,我还要你冒泡排序有何用啊)。
9+
10+
11+ ## 2. 什么时候最慢
12+
13+ 当输入的数据是反序时(写一个for循环反序输出数据不就行了,干嘛要用你冒泡排序呢,我是闲的吗)。
14+
15+
16+ ## 3. 冒泡排序动图演示
17+
18+ ![ 冒泡排序动图演示] ( res/bubbleSort.gif )
19+
20+
21+ ## 4. JavaScript 代码实现
22+
23+ ``` js
24+ function bubbleSort (arr ) {
25+ var len = arr .length ;
26+ for (var i = 0 ; i < len; i++ ) {
27+ for (var j = 0 ; j < len - 1 - i; j++ ) {
28+ if (arr[j] > arr[j+ 1 ]) { // 相邻元素两两对比
29+ var temp = arr[j+ 1 ]; // 元素交换
30+ arr[j+ 1 ] = arr[j];
31+ arr[j] = temp;
32+ }
33+ }
34+ }
35+ return arr;
36+ }
37+ ```
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments