Last active
April 13, 2020 16:06
-
-
Save donpandix/a8964264c09ee85570ff to your computer and use it in GitHub Desktop.
Implementación del ordenamiento de datos a través del algoritmo BubleSort
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
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 ordenamiento { | |
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