Skip to content

Instantly share code, notes, and snippets.

@ivan-avalos
Last active December 3, 2019 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivan-avalos/60eaf070b107bdc3be528b553c8b1b7e to your computer and use it in GitHub Desktop.
Save ivan-avalos/60eaf070b107bdc3be528b553c8b1b7e to your computer and use it in GitHub Desktop.
Método BubbleSort para ordenar ArrayList<Corredor>.
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