
05/02/2011, 09:55
|
| | Fecha de Ingreso: abril-2008
Mensajes: 16
Antigüedad: 16 años, 9 meses Puntos: 0 | |
Respuesta: ayuda... modificar metodo para que ordene descendentemente Hola, mira lo unico que debes cambiar para ke ordene descendentente son algunas condiciones y kedaria asi:
public class Insercion
{
public static void insertionSort(int[] lista)
{
int i, ubicacion, temp;
for(i = 1; i < lista.length; i++) { //Starts at second term, goes until the end of the array.
//En este if cambiar la condicion por mayor que
if(lista[i] > lista[i - 1]) { //If the two are out of order, we move the element to its rightful place.
temp = lista[i];
ubicacion = i;
do { //Keep moving down the array until we find exactly where it's supposed to go.
lista[ubicacion] = lista[ubicacion-1];
ubicacion--;
}
while (ubicacion > 0 && lista[ubicacion-1] < temp);//Aqui pones menor que en lugar de mayor
lista[ubicacion] = temp;
}
}
for(i = 0; i != lista.length; i++)
System.out.print(" " + lista[i]);
}
}
y listo con eso ya ordena como tu kieres |