I am trying to measure the time it takes for my system to sort an Array of 50 thousand random numbers using Selection sort, however i am getting an error. The error i received is null pointed exception. Would someone look at where i am going wrong here
import java.util.Random;
public class SelectionSort {
public static void main(String[] args) {
int arrayOne[] = null;
int arr[] = { 9, 1, 8, 5, 7, -1, 6, 0, 2, 2718 };
int arr1[] = fillArray(arrayOne);
int sortedArr[] = selectionSort(arr1);
System.out.println("Selection sort implemented below");
System.currentTimeMillis();
long start = System.currentTimeMillis();
print(sortedArr);
long elapsed = System.currentTimeMillis() - start;
System.out.println(elapsed);
}
private static int[] fillArray(int[] array) {
Random generator2 = new Random(System.currentTimeMillis());
for (int x = 0; x < 50000; x++) {
array[x] = generator2.nextInt();
}
return array;
}
private static int[] selectionSort(int[] arr) {
int minIndex, tmp;
int n = arr.length;
for (int i = 0; i < n - 1; i++) {
minIndex = i;
for (int j = i + 1; j < n; j++)
if (arr[j] < arr[minIndex])
minIndex = j;
if (minIndex != i) {
tmp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = tmp;
}
}
return arr;
}
private static void print(int[] Array) {
// TODO prints the array
for (int i = 0; i < Array.length; i++)
System.out.print(Array[i] + " ");
System.out.println();
}
}