daily pastebin goal
45%
SHARE
TWEET

Copiuta

a guest Dec 10th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pivot(int a[], int first, int last)
  2. {
  3.     int  p=first;
  4.     int pivotElement=a[first];
  5.  
  6.     for(int i=first+1;i<=last;i++)
  7.     {
  8.         if(a[i]<=pivotElement)
  9.         {
  10.             p++;
  11.             swap(a[i],a[p]);
  12.         }
  13.     }
  14.  
  15.     swap(a[p],a[first]);
  16.  
  17.     return p;
  18. }
  19.  
  20. void quickSort(int a[],int first,int last)
  21. {
  22.     int pivotElement;
  23.  
  24.     if(first<last)
  25.     {
  26.         pivotElement = pivot(a, first, last);
  27.         quickSort(a, first, pivotElement-1);
  28.         quickSort(a, pivotElement+1, last);
  29.     }
  30. }
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