SHARE
TWEET

Untitled

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int partitionn(int arr[100],int p,int q);
  4. void quicksort(int arr[100],int p,int q);
  5. int main()
  6. {
  7.     int p,q,n,i,arr[100];
  8.     cin>>n;
  9.     for(i=0;i<n;i++)
  10.     {
  11.         cin>>arr[i];
  12.     }
  13.     quicksort(arr,0,n-1);
  14.     for(i=0;i<n;i++)
  15.     {
  16.         cout<<arr[i]<<endl;
  17.     }
  18. }
  19. void quicksort(int arr[],int p,int q)
  20. {
  21.     int i,n;
  22.     if(p<q)
  23.     {
  24.         int k=partitionn(arr,p,q);
  25.         quicksort(arr,p,k-1);
  26.         quicksort(arr,k+1,q);
  27.     }
  28.  
  29. }
  30. int partitionn(int arr[],int p,int q)
  31. {
  32.     int i=0,j,n,pivot=0;
  33.     i=p;
  34.     pivot=arr[p];
  35.  
  36.     for(j=p+1;j<=q;j++)
  37.     {
  38.         if(arr[j]<=pivot)
  39.         {
  40.  
  41.  
  42.             swap(arr[i],arr[j]);
  43.             i++;
  44.  
  45.  
  46.         }
  47.     }
  48.     swap(arr[i],pivot);
  49.     return i;
  50.  
  51. }
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