Last active
February 21, 2022 02:10
-
-
Save donpandix/161b25b776eb775d09214fca416b2792 to your computer and use it in GitHub Desktop.
[BUBLE SORT] Ejemplo de ordenamiento con el algoritmo Buble Sort con #Java
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
/** | |
* 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