Skip to content

Commit 2fa1aef

Browse files
committed
JavaScript Ejercicio: 1433 Implementar el Algoritmo de Ordenamiento Insertion Sort en una Función
Implementar el Algoritmo de Ordenamiento Insertion Sort en una Función con el lenguaje de programación JavaScript.
1 parent 99435b9 commit 2fa1aef

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Ejercicio 1433: Implementar el algoritmo de ordenamiento insertion sort en una función.
2+
3+
function insertionSort(datos) {
4+
for (let i = 1; i < datos.length; i++) {
5+
let j = i - 1;
6+
let auxiliar = datos[i];
7+
8+
while (j >= 0 && datos[j] > auxiliar) {
9+
datos[j + 1] = datos[j];
10+
--j;
11+
}
12+
13+
datos[j + 1] = auxiliar;
14+
}
15+
16+
return datos;
17+
}
18+
19+
let primos = [13, 2, 19, 5, 3, 7, 11, 23];
20+
console.log(primos);
21+
22+
console.log();
23+
24+
let resultado = insertionSort(primos);
25+
console.log(resultado);

0 commit comments

Comments
 (0)