N. [GESP]L5-202506-Q3248-S
[GESP]L5-202506-Q3248-S
该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。
关于下述 C++ 代码的快速排序算法,说法错误的是( )。
int randomPartition(std::vector<int>& arr, int low, int high) {
int random = low + rand() % (high - low + 1);
std::swap(arr[random], arr[high]);
int pivot = arr[high];
int i = low - 1;
for (int j = low; j < high; j++) {
if (arr[j] <= pivot) {
i++;
std::swap(arr[i], arr[j]);
}
}
std::swap(arr[i + 1], arr[high]);
return i + 1;
}
void quickSort(std::vector<int>& arr, int low, int high) {
if (low < high) {
int pi = randomPartition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
{{ select(1) }}
- 在
randomPartition函数中,变量i的作用是记录大于基准值的元素的边界 randomPartition函数随机选择基准值,可以避免输入数据特定模式导致的最坏情况下时间复杂度- 快速排序平均时间复杂度是
- 快速排序是稳定排序算法
GESP 2025.06 C++ 五级 全真模拟赛
- 状态
- 已结束
- 规则
- OI
- 题目
- 27
- 开始于
- 2026-11-20 13:32
- 结束于
- 2026-11-25 13:32
- 持续时间
- 2 小时
- 主持人
- 参赛人数
- 0