I have a method called sortTest()
that takes in a number and a sortName()
. The number that it will take in will become the size of the array created and sortName()
is supposed to be the name of the sort it will do.
For example, if I have sortTest(5, bubbleSort)
it should create an array of 5 with random numbers and then take that array of 5 through bubble sort. Here is my code:
public static final int loopSize = 16;
public static int[] makeArray(int n) {
int[] array = new int[n];
for(int d = 0; d < loopSize; d++ ) {
Random r = new Random();
for(int i = 0; i < n; i++) {
for(int k = 0; k < n; k++) {
array[k] = (int)( Math.random()* 1000);
}
}
}
return array;
}
public static void sortTest(int num , sortName() ) {
long Finaltime [];
for(int k = 0; k < loopSize; k++ ) {
arr = makeArray(num);
long startTime = System.nanoTime();
sortName(arr);
endTime = System.nanoTime();
totalTime = endTime - startTime;
}
}