I have written a program in java using selection, bubble and merge sort and I have to print just the time it took to run the sort which works just fine, but how do I sort a sorted list?
I want to see how much faster is it to sort a sorted list, time wise. I'm running the sort on a million integers generated randomly.
Any help would be appreciated.
here's my selection sort......
(btw all my sorts using the same numbers once been generated randomly.
for(int i = 0; i < 10000; i++) {
Array[i] = rn.nextInt(10000);
//System.out.println(Array[i]);
}
Array2 = Arrays.copyOf(Array, 10000);
startSelection = System.nanoTime();
for( int fill = 0; fill < 99999; fill++) {
for (int compare = fill + 1; compare < 10000; compare++) {
if (Array[fill] > Array[compare]) {
int temp = Array[fill];
Array[compare] = temp;
}
}
}
endSelection = System.nanoTime();
resultSelection = endSelection - startSelection;
double seconds = resultSelection / 1000000000.0;
System.out.println(" It took " + resultSelection + " nanoseconds and " + seconds + " seconds to do the selction sort");
output:
It took 33403766 nanoseconds and 0.033403766 seconds to do the selction sort