#include <iostream>
#include <vector>
using namespace std;
void quick_sort(vector<int>& arr, int left, int right) {
if (left >= right ) {
return;
}
if (left < 0 || right >= arr.size()) {
return;
}
int i, j;
i = left;
j = right;
while(i < j) {
while (arr[j] >= arr[left] && i < j) {
j--;
}
while (arr[i] <= arr[left] && i < j) {
i++;
}
if (i < j) {
arr[i]^=arr[j];
arr[j]^=arr[i];
arr[i]^=arr[j];
}
}
arr[left]^=arr[i];
arr[i]^=arr[left];
arr[left]^=arr[i];
quick_sort(arr, left, i - 1);
quick_sort(arr, i + 1, right);
}
int main() {
vector<int> arr = {6, 1, 2, 7, 9, 3, 4, 5, 10, 8};
quick_sort(arr, 0, arr.size()-1);
for (int i = 0; i < arr.size(); i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}
quick_sort
OJ相关文章
最近热门
最常浏览
- 016 推荐系统 | 排序学习(LTR - Learning To Rank)
- 偏微分符号
- i.i.d(又称IID)
- 利普希茨连续条件(Lipschitz continuity)
- (error) MOVED 原因和解决方案
- TextCNN详解
- 找不到com.google.protobuf.GeneratedMessageV3的类文件
- Deployment failed: repository element was not specified in the POM inside distributionManagement
- cannot access com.google.protobuf.GeneratedMessageV3 解决方案
- CLUSTERDOWN Hash slot not served 问题原因和解决办法
×