Last active
July 7, 2022 13:22
-
-
Save salluzziluca/68928c604db01a8124cc41d588bb8a01 to your computer and use it in GitHub Desktop.
Ordenamiento por Inserccion
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 insertion_sort(char vector_desordenado[MAX_VECTOR], char vector_ordenado[MAX_VECTOR], int tope, bool ascendente){ | |
int i, j; | |
for(i = 0; i < tope; i++) | |
vector_ordenado[i] = vector_desordenado[i]; | |
for(i = 0; i < tope; i++){ | |
int elemento_actual = vector_ordenado[i]; | |
j = i-1; | |
if(ascendente){ | |
while (j >= 0 && elemento_actual < vector_ordenado[j]){ | |
vector_ordenado[j+1] = vector_ordenado[j]; | |
j--; | |
} | |
vector_ordenado[j+1] = elemento_actual; | |
} | |
if(!ascendente){ | |
while (j >= 0 && elemento_actual > vector_ordenado[j]){ | |
vector_ordenado[j+1] = vector_ordenado[j]; | |
j--; | |
} | |
vector_ordenado[j+1] = elemento_actual; | |
} | |
} | |
} |
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
def inserccion(lista): | |
largo = len(lista) | |
for i in range(1, largo): | |
elemento = lista[i] | |
j = i-1 | |
while j>=0 and elemento <lista[j]: | |
lista[j+1]=lista[j] | |
j-=1 | |
lista[j+1]=elemento | |
return lista |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment