Advertisement
Guest User

Copiuta

a guest
Dec 10th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement