C++ 快速排序不排序
C++ QuickSort not sorting
void quickSort(vector<double> unsortedData, int leftBound, int rightBound) {
if (leftBound < rightBound) {
double i = partitionStep(unsortedData, leftBound, rightBound);
quickSort(unsortedData, leftBound, i-1);
quickSort(unsortedData, i + 1, rightBound);
}
}
double partitionStep(vector<double> unsortedData, int leftBound, int rightBound) {
double pivot = unsortedData[rightBound];
while (leftBound <= rightBound) {
while ((unsortedData[leftBound] < pivot)) {
leftBound++;
}
while ((unsortedData[rightBound] > pivot)) {
rightBound--;
}
if (unsortedData[leftBound] == unsortedData[rightBound]) {
leftBound++;
} else if (leftBound < rightBound) {
double temp = unsortedData[leftBound];
unsortedData[leftBound] = unsortedData[rightBound];
unsortedData[rightBound] = temp;
}
}
return rightBound;
}
我需要对双精度向量进行排序。此代码运行,但向量未在末尾排序。这可能是我忽略的东西。思潮?
quickSort
例程的高级描述是:
- 将原始向量的副本和范围的端点作为输入
- 用副本做事
- 丢弃副本
这不是特别有用。将输入参数更改为 vector<double>&
,以便您执行的操作引用原始向量而不是副本。
相关文章:
- 如何修复我的快速排序实现?
- C++运行时错误与快速排序算法抛出堆栈转储错误
- 在 MIPS 中快速排序
- 不正确的比较和交换计数器输出用于快速排序功能
- 使用 std::vector C++快速排序,EXC_BAD_ACCESS代码 2
- 使用快速排序对 C++ 中的可视化工具错误进行排序
- 快速排序 - 三个中位数枢轴选择 - 某些元素顺序不正确
- 并行快速排序分区中的隔离错误
- 实现 3 路分区以实现快速排序
- 为什么这个快速排序实现给出了一个奇怪的输出
- 我的快速排序在对预排序的项目进行排序时失败,如何改进?
- 快速排序不适用于大型数组
- 快速排序;分段错误,但找不到位置?
- 快速排序函数在快速排序算法中如何工作?
- 3路随机快速排序分区功能
- 在最坏的情况下试验快速排序.它运行良好,但在最坏的情况下发生未知错误.我想
- 当给出预先排序的输入时,为什么我的快速排序实现很慢
- 我想要一个改变数组快速排序的2个数字的函数
- C++一个具有 2 个参数(___ _____,整数长度)的函数中的快速排序
- 迭代快速排序方法的分区算法问题