14 lines
378 B
Plaintext
14 lines
378 B
Plaintext
public void insercion() {
|
|
for (int i = 1; i < elementos; i++) {
|
|
// Guardar el elemento en un variable temporario.
|
|
int temp = array[i];
|
|
int j = i;
|
|
// Mover los valores hasta que hay una mas pequeño.
|
|
while (j > 0 && array[j-1] >= temp) {
|
|
array[j] = array[j-1];
|
|
--j;
|
|
}
|
|
// Poner el valor temporario despues de los valores mas pequeños.
|
|
array[j] = temp;
|
|
}
|
|
} |