private static <T> void shuffle(T[] array){
if(array==null || array.length < 2){
return;
}
for(int i=1;i<array.length;i++){
int a = rng.nextInt(i+1);
System.out.println(a);
T temp = array[a];
System.out.println(temp);
array[a] = array[i];
array[i] = temp;
}
}
static boolean checkSorted(ISort sorter, int size) {
Integer[] data = new Integer[size];
shuffle(data);
}
The output of printing integer a and T temp: 0 null 2 null 0 null 2 null 0 null 4 null 7 null 8 null 6
I'm not sure why the temp is null instead of integer. Can anyone explain to me? What should i do to modify this code to make it work?
Aucun commentaire:
Enregistrer un commentaire