This commit is contained in:
krahets
2023-02-08 22:16:25 +08:00
parent 30ed83e5b1
commit af3542e3c0
17 changed files with 258 additions and 100 deletions
+11 -2
View File
@@ -398,7 +398,6 @@ comments: true
quickSort(nums, left, pivot - 1);
quickSort(nums, pivot + 1, right);
}
```
=== "Swift"
@@ -679,7 +678,17 @@ comments: true
// 将中位数交换至数组最左端
swap(nums, left, med);
// 以 nums[left] 作为基准数
// 下同省略...
int i = left, j = right;
while (i < j)
{
while (i < j && nums[j] >= nums[left])
j--; // 从右向左找首个小于基准数的元素
while (i < j && nums[i] <= nums[left])
i++; // 从左向右找首个大于基准数的元素
swap(nums, i, j); // 交换这两个元素
}
swap(nums, i, left); // 将基准数交换至两子数组的分界线
return i; // 返回基准数的索引
}
```