Não deixe de conferir o gráfico de desempenho deste código!
//Autor: Filipe Areias NévolaNão deixe de conferir a explicação teórica desse algoritmo!
//Ano: 2008
//Programa: Quick-Sort Random
//Licensa: Você pode usar e alterar, mas deve manter o Autor
//Chamada principal
void randQuickSort(int t){
int p=0,r=t-1;
randQuick(p,r);
}
void randQuick(int p,int r){
int q;
if(p<r){
q=randPartition(p,r);
randQuick(p,q-1);
randQuick(q+1,r);
}
}
int randPartition(int p,int r){
int i=rand()%(p-r);
i+=p;
troca(v[r],v[i]);
return partition(p,r);
}
int partition(int p,int r){
int i,j;
int x;
x=v[r];
i=p-1;
for(j=p;j<=r-1;++j){
if(v[j]<=x){
i++;
troca(v[i],v[j]);
}
}
troca(v[i+1],v[r]);
return i+1;
}