C++快速排序
作者:互联网
#include <bits/stdc++.h>;
using namespace std;
void quickSort(int arry[], int low, int high);
int main() {
int N;
cin >> N;
int a[N];
for (int i = 0; i < N; i++) {
cin >> a[i];
}
quickSort(a, 0, N - 1);
for (int i = 0; i < N; i++) {
cout << a[i] << " ";
}
return 0;
}
void quickSort(int arry[], int low, int high) {
int l = low;
int r = high;
int key = arry[l];
if (low >= high) {
return ;
}
while (l < r) {
while (l < r && arry[r] > key) {
r--;
}
arry[l] = arry[r];
while (l < r && arry[l] < key) {
l++;
}
arry[r] = arry[l];
}
arry[l] = key;
quickSort(arry, low, l - 1);
quickSort(arry, l + 1, high);
}
标签:int,quickSort,C++,high,++,key,排序,快速,arry 来源: https://blog.csdn.net/m0_56174465/article/details/121941440