Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pivot(int a[], int first, int last)
- {
- int p=first;
- int pivotElement=a[first];
- for(int i=first+1;i<=last;i++)
- {
- if(a[i]<=pivotElement)
- {
- p++;
- swap(a[i],a[p]);
- }
- }
- swap(a[p],a[first]);
- return p;
- }
- void quickSort(int a[],int first,int last)
- {
- int pivotElement;
- if(first<last)
- {
- pivotElement = pivot(a, first, last);
- quickSort(a, first, pivotElement-1);
- quickSort(a, pivotElement+1, last);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement