mercredi 1 avril 2015

Error in if statement. Merging

I'm trying to get this merge sort method done but for some reason I am shown an error "The operator <= is undefined for the argument type(s) T, T"


for the if statement



if(a[beginHalf1] <= a[beginHalf2])
{

tempArray[index] = a[beginHalf1];
beginHalf1++;
}


here is the full code



public static <T extends Comparable<? super T>>
void merge(T[] a, T[] tempArray, int first, int mid, int last){


int beginHalf1 = first;
int endHalf1 = mid;
int beginHalf2 = mid +1;
int endHalf2 = last;
int index = 0;

while((beginHalf1 <= endHalf1) && (beginHalf2 <= endHalf2) )
{

if(a[beginHalf1] <= a[beginHalf2]){

tempArray[index] = a[beginHalf1];
beginHalf1++;
}

else
{
tempArray[index]=a[beginHalf2];
beginHalf2++;
}
index++;
}




} // end merge


any help would be great thanks!


Aucun commentaire:

Enregistrer un commentaire