Skip to content

Instantly share code, notes, and snippets.

@ilmoralito
Created June 4, 2022 15:16
Show Gist options
  • Save ilmoralito/97a8e4d10386c770951a3aad2e3f56e4 to your computer and use it in GitHub Desktop.
Save ilmoralito/97a8e4d10386c770951a3aad2e3f56e4 to your computer and use it in GitHub Desktop.
Algoritmo ordenamiento_por_insercion
T = 10
Dimension arreglo[T]
arreglo[0] <- 100
arreglo[1] <- 20
arreglo[2] <- 5
arreglo[3] <- 1
arreglo[4] <- 16
arreglo[5] <- 3
arreglo[6] <- 4
arreglo[7] <- 8
arreglo[8] <- 6
arreglo[9] <- 15
Para i <- 1 Hasta T - 1 Hacer
j <- i - 1
siguiente_elemento <- arreglo[i]
Mientras (j >= 0) Y (arreglo[j] > siguiente_elemento) Hacer
arreglo[j + 1] <- arreglo[j]
j <- j - 1
FinMientras
arreglo[j + 1] <- siguiente_elemento
FinPara
Para i <- 0 Hasta T - 1 Hacer
Escribir "arreglo[",i,"]=",arreglo[i]
FinPara
FinAlgoritmo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment