File tree Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Expand file tree Collapse file tree 3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 11## 目录
22
33### 基本数据结构
4-
4+ - [ 数组] ( )
5+ - [ 链表] ( ./Linked_list )
56#### TODO:
67- [ 堆] ( ./Heap )
78- [ 栈] ( ./Stack )
1112- [ 双端队列] ( ./Deque )
1213
1314### 基本排序算法
15+ - [ 快速排序] ( sorts/quick_sort )
16+ - [ 冒泡排序] ( sorts/bubble_sort )
17+ - [ 插入排序] ( sorts/insertion_sort )
18+ - [ 归并排序] ( sorts/merge_sort )
19+ - [ 选择排序] ( sorts/selection_sort )
20+ - [ 希尔排序] ( sorts/shell_sort )
1421
1522### 其他数据结构
1623#### TODO:
Original file line number Diff line number Diff line change 1515## 图示
1616
1717![ 冒泡排序算法] ( ./img/Bubble_sort_animation.gif )
18+
1819从图中可以看到,冒泡只有最上面的会保证顺序排列,剩下的(未排序元素)是逐渐(向有序)“靠拢”的过程。
1920
2021![ 冒泡排序实例] ( ./img/bubble_sort_example.gif )
Original file line number Diff line number Diff line change @@ -23,6 +23,12 @@ def quick_sort(unsorted_collection):
2323 cmp_base = unsorted_collection [0 ] # 取出第一个作为比较基准
2424 left_col = [item for item in unsorted_collection [1 :] if item <= cmp_base ] # 如果希望降序排列,只需分治点两边调换即可
2525 right_col = [item for item in unsorted_collection [1 :] if item > cmp_base ]
26+ '''
27+ left_col = []
28+ right_col = []
29+ for item in unsorted_collection[1:]:
30+ left_col.append(item) if item <= cmp_base else right_col.append(item)
31+ '''
2632 return quick_sort (left_col ) + [cmp_base ] + quick_sort (right_col ) # 对左右两边的序列使用递归,之后拼接;注意中间的元素要“还原”
2733
2834
You can’t perform that action at this time.
0 commit comments