Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- using namespace std;
- void qsort(int* A, int L, int R) {
- if (R - L <= 1) return;
- int mid = A[L + rand() % (R - L)];
- int x = L, y = L;
- for (int i = L; i < R; ++i)
- if (A[i] < mid) {
- swap(A[x], A[i]);
- if (x != y) swap(A[y], A[i]);
- ++x; ++y;
- }
- else if (A[i] == mid) {
- swap(A[y], A[i]);
- ++y;
- }
- qsort(A, L, x);
- qsort(A, y, R);
- }
- int main() {
- int g;
- cin >> g;
- int* H = new int[g];
- for (int i = 0; i < g; i++) {
- cin >> H[i];
- }
- qsort(H, 0, g);
- for (int i = 0; i < g; i++) {
- cout << H[i] << " ";
- }
- system("Pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement