Last active
March 10, 2023 22:21
-
-
Save zendar426/0b64ad9208b465298b852e1b8ec4a13f to your computer and use it in GitHub Desktop.
#orden #Java
This file contains 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
// usar con su respectiva interfaz | |
public static void bubbleSort(Objeto[] objetos) { | |
for (int i = 0; i < personas.length - 1; i++) { | |
for (int j = 0; j < personas.length - 1; j++) { | |
if (personas[j].compareTo(personas[j + 1]) > 0) { | |
Persona aux = personas[j]; | |
personas[j] = personas[j + 1]; | |
personas[j + 1] = aux; | |
} | |
} | |
} | |
} | |
//MODO DE USO, PASAR EN EL SORT LAS COSAS A ORDENARSE | |
@Override | |
public int compareTo(Objeto objeto) { | |
if(this.atributo>objeto.atributo){ | |
return 1; | |
}else if(this.atributo == objeto.atributo){ | |
return 0; | |
}else{ | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment