Last active
August 17, 2021 04:27
-
-
Save CrysoK/7499a1022c45a8420660909e64f9dc4b to your computer and use it in GitHub Desktop.
Implementación en C del método de ordenamiento por intercambio directo ("burbuja") inspirado en el pseudocódigo de https://visualgo.net/en/sorting.
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 bubbleSort(int arreglo[], int elementos) { | |
int yaOrdenados = 0; | |
int huboIntercambio; | |
int primeroSinOrdenar = 0; | |
do { | |
huboIntercambio = 0; | |
int i = primeroSinOrdenar; | |
primeroSinOrdenar++; | |
while(i < elementos - yaOrdenados - 1) { | |
if(arreglo[i] > arreglo[i + 1]) { | |
int aux = arreglo[i]; | |
arreglo[i] = arreglo[i + 1]; | |
arreglo[i + 1] = aux; | |
if(huboIntercambio == 0) primeroSinOrdenar = i > 0 ? i - 1 : 0; | |
huboIntercambio = 1; | |
} | |
i++; | |
} | |
yaOrdenados++; | |
} while(huboIntercambio == 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment