Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. int QuickSort1(int v[], int n){
  2.  
  3.         int pivot = (v[0]+v[n-1])/2;/*Escolhe elemento aleatorio como pivot*/
  4.         int a=0, b=n-1, i, aux;
  5.  
  6.         if(n==1) return;
  7.         /*Particiona*/
  8.         while(a<=b){
  9.  
  10.                 if(v[a]>pivot && v[b]<=pivot) {
  11.                         aux=v[a];
  12.                         v[a]=v[b];
  13.                         v[b]=aux;       /*Troca*/
  14.                         a++;
  15.                         b--;
  16.                 }else {
  17.                         if(v[a]<=pivot) a++;
  18.                         if(v[b]>pivot) b--;
  19.                 }
  20.         }
  21.         /*Se i<=b entao v[i]<=p, se j>b entao v[j]>p*/
  22.         QuickSort1(v,b+1);
  23.         QuickSort1(v+b+1,n-b-1);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement