Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- using namespace std;
- long n, a[100001];
- void qsort(long l,long r){
- long h,i,j;
- if (l<r){
- h=a[(l+r)/2];
- i=l;j=r;
- while (i<=j){
- while (a[i]<h) i++;
- while (a[j]>h) j--;
- if (i<=j){
- if (i<j){
- swap(a[i],a[j]);cout<<i<<" "<<j<<endl;
- }
- i++;
- j--;
- }
- }
- qsort(l,j);
- qsort(i,r);
- }
- }
- int main(){
- cin>>n;
- for(int i=1;i<=n;i++){
- cin>>a[i];
- }
- qsort(1,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment