Created
September 20, 2019 13:39
-
-
Save Tlaloc-Es/e8f413b668e59413d9b657ad42cf2152 to your computer and use it in GitHub Desktop.
Comparacion
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
package hackerrang; | |
import java.io.FileWriter; | |
import java.util.Arrays; | |
import java.util.PriorityQueue; | |
import java.util.Random; | |
public class Lista { | |
public static void main(String[] args) { | |
testArray(100000); | |
testMonticulo(100000); | |
} | |
public static void testArray(int cantidad) { | |
int[] list = new int[cantidad]; | |
try{ | |
long TInicio, TFin, tiempo; | |
TInicio = System.currentTimeMillis(); | |
for(int i = 0; i < cantidad; i++) { | |
list[i] = getRandomNumberInRange(0, 2000000); | |
Arrays.sort(list); | |
} | |
TFin = System.currentTimeMillis(); | |
tiempo = TFin - TInicio; | |
System.out.println("Tiempo de ejecución en milisegundos de arrays: " + tiempo); | |
}catch(Exception e){System.out.println(e); | |
} | |
} | |
public static void testMonticulo(int cantidad) { | |
PriorityQueue pq = new PriorityQueue<Integer>(); | |
int[] list = new int[cantidad]; | |
try{ | |
long TInicio, TFin, tiempo; | |
TInicio = System.currentTimeMillis(); | |
for(int i = 0; i < cantidad; i++) { | |
pq.add(i); | |
} | |
TFin = System.currentTimeMillis(); | |
tiempo = TFin - TInicio; | |
System.out.println("Tiempo de ejecución en milisegundos de monticulos: " + tiempo); | |
}catch(Exception e){System.out.println(e); | |
} | |
} | |
private static int getRandomNumberInRange(int min, int max) { | |
if (min >= max) { | |
throw new IllegalArgumentException("max must be greater than min"); | |
} | |
Random r = new Random(); | |
return r.nextInt((max - min) + 1) + min; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment