Advertisement
anon20016

L

Nov 14th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #define _CRT_SECURE_NO_DEPRECATE
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <map>
  7. #include <set>
  8. #include <algorithm>
  9.  
  10. #define li long long
  11.  
  12. using namespace std;
  13.  
  14. int a[1000001];
  15.  
  16. void quickSortR(int *a, int n) {
  17. int i = 0, j = n;
  18. int t, temp;
  19. int p = a[n / 2];
  20.  
  21. do {
  22. while (a[i] < p) i++;
  23. while (a[j] > p) j--;
  24.  
  25. if (i <= j) {
  26. swap(a[i], a[j]);
  27. i++; j--;
  28. }
  29. } while (i <= j);
  30.  
  31. if (j > 0) quickSortR(a, j);
  32. if (n > i) quickSortR(a + i, n - i);
  33. }
  34.  
  35. int main() {
  36. int n;
  37. cin >> n;
  38. for (int i = 0; i < n; i++) {
  39. cin >> a[i];
  40. }
  41. quickSortR(a, n - 1);
  42. for (int i = 0; i < n; i++) {
  43. cout << a[i] << ' ';
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement