Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created December 30, 2020 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/f21ddd1c7b5f8bb95a1845af559377da to your computer and use it in GitHub Desktop.
Save parzibyte/f21ddd1c7b5f8bb95a1845af559377da to your computer and use it in GitHub Desktop.
void ordenarArreglo()
{
int x;
for (x = 0; x < CANTIDAD_PERSONAS; x++)
{
int indiceActual;
for (indiceActual = 0; indiceActual < CANTIDAD_PERSONAS - 1;
indiceActual++)
{
int indiceSiguienteElemento = indiceActual + 1;
// Ordenar por altura, de manera descendente
if (personas[indiceActual].altura < personas[indiceSiguienteElemento].altura)
{
// Intercambiar
memcpy(&temporal, &personas[indiceActual], sizeof(struct persona));
memcpy(&personas[indiceActual], &personas[indiceSiguienteElemento], sizeof(struct persona));
memcpy(&personas[indiceSiguienteElemento], &temporal, sizeof(struct persona));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment