Skip to content

Instantly share code, notes, and snippets.

@zendar426
Last active March 10, 2023 22:21
Show Gist options
  • Save zendar426/0b64ad9208b465298b852e1b8ec4a13f to your computer and use it in GitHub Desktop.
Save zendar426/0b64ad9208b465298b852e1b8ec4a13f to your computer and use it in GitHub Desktop.
#orden #Java
// 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