Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 3, 2021 02:25
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/f2b1e3c0458177280f02468ca20523f4 to your computer and use it in GitHub Desktop.
Save parzibyte/f2b1e3c0458177280f02468ca20523f4 to your computer and use it in GitHub Desktop.
static void ordenarBurbujaCadenas(string[] arreglo)
{
for (int x = 0; x < arreglo.Length; x++)
{
// Recuerda que el -1 es porque no queremos llegar al final ya que hacemos
// un indiceActual + 1 y si fuéramos hasta el final, intentaríamos acceder a un valor fuera de los límites
// del arreglo
for (int indiceActual = 0; indiceActual < arreglo.Length - 1;
indiceActual++)
{
int indiceSiguienteElemento = indiceActual + 1;
// Si el actual es mayor que el que le sigue a la derecha...
if (arreglo[indiceActual].CompareTo(arreglo[indiceSiguienteElemento]) > 0)
{
string temporal = arreglo[indiceActual];
arreglo[indiceActual] = arreglo[indiceSiguienteElemento];
arreglo[indiceSiguienteElemento] = temporal;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment