SHARE
TWEET

Untitled

a guest Nov 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <algorithm>
  5. int t[31];
  6.  
  7. void qsort(int l, int p) {
  8.     int m = l;
  9.     for (int i = l+1; i <= p; ++i) {
  10.         if(t[i] <= t[l])
  11.             std::swap(t[++m], t[i]);
  12.     }
  13.     std::swap(t[l], t[m]);
  14.     if (m - l > 1) qsort(l, m-1);
  15.     if (p - m > 1) qsort(m+1, p);
  16. }
  17.  
  18. int main() {
  19.     srand(time(NULL));
  20.     for (int i = 0; i < 30; ++i) {
  21.         int r = rand()%99 + 10;
  22.         t[i] = r;
  23.         std::cout << t[i] << ' ';;
  24.     }
  25.     std::random_shuffle(t, t+29);
  26.     qsort(0, 29);
  27.     std::cout << '\n';
  28.     for (int i = 0; i < 30; ++i)
  29.         std::cout << t[i] << ' ';
  30.  
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top