/** @param args */ public static void main(String[] args) { // TODO Auto-generated method stub double[] mesto = new double[3000]; int[] mesta = new int[3000]; int mean = 5000; int std = 1300; int vysledek = 0; for (int i = 0; i < 3000; i++) { mesto[i] = mean + std * r.nextGaussian(); mesta[i] = (int) (mesto[i]); // System.out.println(mesta[i]); vysledek = vysledek + mesta[i]; } Quick.serad(mesta); for (int i = 0; i < 3000; i++) { System.out.println(i + ". mesto: " + mesta[i]); } System.out.println("Celkem lidi: " + vysledek); }
/////// Algorithm Runs public double simpleQuick(int run) { double simpAnswer = 0; double median5 = 0, median10 = 0, median20 = 0, pivot = 0; String sortType; if (run == 1) { sortType = rand; } else if (run == 2) { sortType = sorted; } else { sortType = reversed; } for (int i = 0; i < trialNumber; i++) { System.out.println("\n" + toString(simpleQ, sortType)); System.out.print("Before sorting: "); printArray(); long start = System.nanoTime(); Quick.quickSort(myArray, myArray.length); // Simple quick Sort long finish = System.nanoTime(); double delta = finish - start; printEnd(delta); // for simple quicksort simpAnswer += delta; // add the delta to the answer myArray = copyArray.clone(); System.out.println("\n" + toString(Med + " (5)", sortType)); System.out.print("Before sorting: "); printArray(); median5 += Median(5); // base case 5 printEnd(median5); myArray = copyArray.clone(); System.out.println("\n" + toString(Med + " (10)", sortType)); System.out.print("Before sorting: "); printArray(); median10 += Median(10); // base case 10 printEnd(median10); myArray = copyArray.clone(); System.out.println("\n" + toString(Med + " (20)", sortType)); System.out.print("Before sorting: "); printArray(); median20 += Median(20); // base case 20 printEnd(median20); myArray = copyArray.clone(); System.out.println("\n" + toString(randPivot + " (5)", sortType)); System.out.print("Before sorting: "); printArray(); pivot += pivotFunction(); // pivot printEnd(pivot); if (run == 1) { fillArrayRandom(); // fill array randomly again } else if (run == 2) { fillArraySorted(); // fill array sorted } else { fillArrayReverse(); // fill array reversed } } medianAnswer5 = (((double) median5 / 1000000000) / trialNumber); // MedianAnswer5 medianAnswer10 = (((double) median10 / 1000000000) / trialNumber); // MedianAnswer10 medianAnswer20 = (((double) median20 / 1000000000) / trialNumber); // MedianAnswer10 randomPivot = (((double) pivot / 1000000000) / trialNumber); // random Pivot return (((double) simpAnswer / 1000000000) / trialNumber); }