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);

}

上一篇:CUDD UM


下一篇:反射:InvokeMethod 活动调用多种方法的方法配置要点