File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -73,13 +73,37 @@ const insertSort = function (nums: number[]) {
73
73
#### 归并排序
74
74
75
75
``` java
76
-
76
+
77
77
```
78
78
79
79
#### 快速排序
80
80
81
81
``` java
82
-
82
+ const quickSort = (nums: number[], start: number, end: number) = > {
83
+ let left = start,
84
+ right = end
85
+ const pivot = start
86
+ while (left < right) {
87
+ while (left < right && nums[right] > nums[pivot]) {
88
+ right--
89
+ }
90
+ while (left < right && nums[left] < nums[pivot]) {
91
+ left++
92
+ }
93
+ if (nums[left] === nums[right] && left < right) {
94
+ left++
95
+ } else {
96
+ ;[nums[left], nums[right]] = [nums[right], nums[left]]
97
+ }
98
+ }
99
+ if (start < left - 1 ) {
100
+ quickSort(nums, start, left - 1 )
101
+ }
102
+ if (right + 1 < end) {
103
+ quickSort(nums, right + 1 , end)
104
+ }
105
+ return nums
106
+ }
83
107
```
84
108
85
109
#### 堆排序
You can’t perform that action at this time.
0 commit comments