private static void sort(int[] values, int from, int to) { int n = to - from + 1; if (n < 2) { return; } Ej1.swap(values, from, (int) (Math.random() * n) + from); int k = from; for (int i = from + 1; i <= to; i++) { if (values[i] < values[from]) { Ej1.swap(values, ++k, i); } } Ej1.swap(values, k, from); sort(values, from, k - 1); sort(values, k + 1, to); }
public static void ej2() { int[] sizes = new int[] {5000, 10000, 20000, 40000, 80000}; long start, time; for (int size : sizes) { int[] array = Ej1.createRandomArray(size); System.out.println(Arrays.toString(array)); start = System.currentTimeMillis(); quicksort(array); time = System.currentTimeMillis() - start; System.out.println(Arrays.toString(array)); System.out.println("Size: " + size + " Time: " + time + " ms"); } }