Skip to content

Instantly share code, notes, and snippets.

@donpandix
Last active February 21, 2022 02:10
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 donpandix/161b25b776eb775d09214fca416b2792 to your computer and use it in GitHub Desktop.
Save donpandix/161b25b776eb775d09214fca416b2792 to your computer and use it in GitHub Desktop.
[BUBLE SORT] Ejemplo de ordenamiento con el algoritmo Buble Sort con #Java
/**
* Busqueda de tipo BubleSort
*/
class BubleSort {
BubleSort (int ... array) {
long time_start, time_end;
time_start = System.currentTimeMillis();
for(int i = 0; i < array.length; i++) {
for(int j = i + 1; j < array.length; j++) {
if(array[j] < array[i]) {
int temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
time_end = System.currentTimeMillis();
for(int k:array)
System.out.println(k);
System.out.println("El ordenamiento con Bubble Sort tomó: " + ( time_end - time_start ) + " milisegundos.");
}
}
public class busqueda {
public static void main (String[] args) {
System.out.println("Generación del arreglo de los datos a ordenar");
// Generacion del arreglo a ordenar
int largoArreglo = 10;
try {
largoArreglo = Integer.parseInt( args[0] );
} catch (Exception e) { }
int[] disorderArray = new int[largoArreglo];
for (int i = 0; i < largoArreglo; i++)
disorderArray[i] = Math.round(((float) Math.random() * largoArreglo));
System.out.println("Inicio del ordenamiento");
new BubleSort(disorderArray);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment