Created
April 5, 2013 14:03
-
-
Save lMooka/5319503 to your computer and use it in GitHub Desktop.
QuickSort feito em Sala de aula por Apolinário.
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
void QuickSort(int* v, int i, int f) | |
{ | |
int pivo,aux; | |
if(i>=f) | |
return; | |
if((f-i) ==1) | |
{ | |
if(v[f] < v[i]) | |
{ | |
aux=v[f]; | |
v[f] = v[i]; | |
v[i] = aux; | |
} | |
return; | |
} | |
} | |
int Particiona(int * v, int i, int f) | |
{ | |
int dir, esq, aux, pivo; | |
pivo = f; | |
dir = f - 1; | |
esq = i; | |
while (esq < dir) | |
{ | |
while (v[esq] < v[pivo]) | |
esq++; | |
while (v[esq] < v[pivo]) | |
dir--; | |
if(esq < dir) | |
{ | |
aux = v[dir]; | |
v[dir] = v[esq]; | |
v[esq]=aux; | |
aux = v[pivo]; | |
v[pivo] = v[esq]; | |
v[esq] = aux; | |
aux = v[pivo]; | |
v[pivo] = v[esq]; | |
v[esq] = aux; | |
return esq; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment