Godrambo

R4H

Apr 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3.  
  4. using namespace std;
  5.  
  6. long n, a[100001];
  7.  
  8. void qsort(long l,long r){
  9.     long h,i,j;
  10.     if (l<r){
  11.         h=a[(l+r)/2];
  12.         i=l;j=r;
  13.         while (i<=j){
  14.             while (a[i]<h) i++;
  15.             while (a[j]>h) j--;
  16.             if (i<=j){
  17.                 if (i<j){
  18.                     swap(a[i],a[j]);cout<<i<<" "<<j<<endl;
  19.                 }
  20.                 i++;
  21.                 j--;
  22.             }
  23.         }
  24.         qsort(l,j);
  25.         qsort(i,r);
  26.     }
  27. }
  28.  
  29. int main(){
  30.     cin>>n;
  31.     for(int i=1;i<=n;i++){
  32.         cin>>a[i];
  33.     }
  34.     qsort(1,n);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment