I am trying to find the middle index in an array (of type long) The problem im solving specifically asks for a long to return, so I cant change the signature I want to find the pivot point, in my quicksort code, but I get an error "possible lossy conversion from long to int" I understand that I may lose some information when dividing, but I want to bypass it here is the code containing the error:
public static long partition(long[] array, long left, long right){
long i = left, j = right;
long tmp;
long pivot = array[(left + right) / 2]; // <-----ERROR HERE <------
while(i <= j) {
while(array[i] < pivot){
i--;
}
while(array[j] > pivot) {
j--;
}
if(i <= j) {
tmp =array[i];
array[i] = array[j];
array[j] = tmp;
i++;
j--;
}
}
return i;
}
use "array[index]", this "index" must be int. so
long pivot = array[(int)((left + right) / 2)];
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments