Advertisement
High_Light

sortirovka bistraja

Nov 30th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. void swap(int a,int b){
  8.     int c;
  9.     c = a;
  10.     a = b;
  11.     b = c;
  12. }
  13.  
  14. void qsort1 (int *a, int n){
  15.     if (n > 1){
  16.         int l = 0;
  17.         int r = n - 1;
  18.         int c = a[rand()%n];
  19.                 while ( l < r ) {
  20.                     while (a[l] < c){
  21.                         l++;
  22.                     }
  23.                     while (a[r] > c){
  24.                         r--;
  25.                     }
  26.                 }
  27.                 if (l <= r)
  28.                     swap (a[l++], a[r--]);
  29.                 while ()
  30.                 qsort1 (a, n + 1);
  31.                 qsort1 (a + l, n - l);
  32.     }
  33. }
  34.  
  35. int main()
  36. {
  37.     int n = 8;
  38.     int a[n] = {0,9,76,5,6,4,24,1};
  39.     qsort1 (a,n);
  40.     for (int i = 0; i < n; i++)
  41.         cout << a[i] << endl;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement