Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int QuickSort1(int v[], int n){
- int pivot = (v[0]+v[n-1])/2;/*Escolhe elemento aleatorio como pivot*/
- int a=0, b=n-1, i, aux;
- if(n==1) return;
- /*Particiona*/
- while(a<=b){
- if(v[a]>pivot && v[b]<=pivot) {
- aux=v[a];
- v[a]=v[b];
- v[b]=aux; /*Troca*/
- a++;
- b--;
- }else {
- if(v[a]<=pivot) a++;
- if(v[b]>pivot) b--;
- }
- }
- /*Se i<=b entao v[i]<=p, se j>b entao v[j]>p*/
- QuickSort1(v,b+1);
- QuickSort1(v+b+1,n-b-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement