daily pastebin goal
56%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3.  
  4. using namespace std;
  5.  
  6. int x[2000];
  7.  
  8. int n;
  9.  
  10. int poz(int p,int u)
  11. {
  12.     int piv,aux,k;
  13.  
  14.     piv=x[p];
  15.  
  16.     while (p<u)
  17.     {
  18.         if (x[p]>x[u])
  19.         {
  20.             aux=x[p];
  21.  
  22.             x[p]=x[u];
  23.  
  24.             x[u]=aux;
  25.  
  26.         }
  27.  
  28.         if (x[p]==piv)
  29.  
  30.             u--;
  31.  
  32.         else p++;
  33.  
  34.     }
  35.  
  36.     k=p;
  37.  
  38.     return k;
  39.  
  40. }
  41.  
  42.  
  43.  
  44. void quick(int p,int u)
  45.  
  46. {
  47.     int k;
  48.  
  49.     if (p<u)
  50.     {
  51.         k=poz(p,u);
  52.  
  53.         quick(p,k-1);
  54.  
  55.         quick(k+1,u);
  56.     }
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64. int main()
  65. {
  66.  
  67.     cin>>n;
  68.  
  69.     for(int i=1; i<=n; i++)
  70.  
  71.     {
  72.  
  73.         cin>>x[i];
  74.  
  75.     }
  76.  
  77.     quick(1,n);
  78.  
  79.     for(int i=1; i<=n; i++)
  80.  
  81.         cout<<x[i]<<' ';
  82.  
  83.     return 0;
  84.  
  85. }
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