Skip to content

Instantly share code, notes, and snippets.

@lMooka
Created April 5, 2013 14:03
Show Gist options
  • Save lMooka/5319503 to your computer and use it in GitHub Desktop.
Save lMooka/5319503 to your computer and use it in GitHub Desktop.
QuickSort feito em Sala de aula por Apolinário.
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