public class GenericSort<G extends Comparable> {
private G[] integerarray;
public GenericSort(G[] inputarray){
this.integerarray = inputarray;
//check empty array
if (integerarray ==null || integerarray.length==0){return;}
quickSort(0,integerarray.length-1);
}
public void quickSort(int low, int high){
int i = low;
int j = high;
//set Pivot
G pivot = integerarray[low + (high-low)/2];
while(i<=j){
//check left
while(integerarray[i]<pivot){i++;}
//check right
while(pivot<integerarray[j]){j--;}
//swap
if(i<=j){
G temp = integerarray[i];
integerarray[i] = integerarray[j];
integerarray[j] = temp;
i++;
j--;
}
}
//recursion
if(low<j){quickSort(low,j);}
if(i<high){quickSort(i,high);}
}
}
ici la ligne:Générique Trier- problème de comparision
while(integerarray[i]<pivot) {
i++;
} &
while(integerarray[i]<pivot){i++;}
donne erreur car comarision n'est pas autorisé entre les types inconnus. Donc j'ai étendu G de comparable. Ne marche toujours pas. Comment le résoudre?
formater le code s'il vous plaît. – Nishant