Created
July 30, 2014 23:05
-
-
Save reinaldorauch/ce822d6266413fc746e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Gera o ponto de divisão da partição | |
* @param p inicio do array | |
* @param r final do array | |
* @return ponto de divisão da partição | |
*/ | |
int partition(p, r) { | |
int piv = array[p], i = (p - 1), j = (r + 1), temp = 0; | |
while(1) { | |
while(array[--j] > piv); | |
while(array[++i] < piv); | |
if(i < j) { | |
temp = array[i]; | |
array[i] = array[j]; | |
array[j] = temp; | |
} else | |
return j; | |
} | |
} | |
/** | |
* Implementação do quicksort | |
* @param p início do vetor | |
* @param r fim do vetor | |
*/ | |
void quickSort(int p, int r) { | |
int q = 0; | |
if(p < r) { | |
q = partition(p, r); | |
quickSort(p, q); | |
quickSort(q + 1, r); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment