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[]) {
7373#### 归并排序
7474
7575``` java
76-
76+
7777```
7878
7979#### 快速排序
8080
8181``` 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+ }
83107```
84108
85109#### 堆排序
You can’t perform that action at this time.
0 commit comments