Last active
December 3, 2019 04:09
-
-
Save ivan-avalos/60eaf070b107bdc3be528b553c8b1b7e to your computer and use it in GitHub Desktop.
Método BubbleSort para ordenar ArrayList<Corredor>.
This file contains hidden or 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
public static void Ordenar(ArrayList<Corredor> list) | |
{ | |
Corredor temp; | |
if (list.size()>1) // check if the number of orders is larger than 1 | |
{ | |
for (int x=0; x<list.size(); x++) // bubble sort outer loop | |
{ | |
for (int i=0; i < list.size() - x - i; i++) { | |
if (list.get(i).tiempoMin - list.get(i+1).tiempoMin > 0) | |
{ | |
temp = list.get(i); | |
list.set(i,list.get(i+1) ); | |
list.set(i+1, temp); | |
} | |
} | |
} | |
} | |
} | |
// Como utilizar la función. | |
ArrayList<Corredor> corredores = ...; | |
datosCorredores.Ordenar(corredores); | |
// Tu arreglo ya está ordenado, :D | |
// Modificar el tiempo de un corredor. | |
public static void modificar (ArrayList<Corredor> corredores) | |
{ | |
int n = ...; // lo sacas de JOptionPane | |
int tiempo = ...; // lo sacas de JOptionPane | |
Corredor corredor = corredores.get(n); | |
corredor.tiempoMin = tiempo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment