Hello again,
I am writing a median of three quick sort algorithm and I just made my findMedian() method. I return type comparable, but
the compiler says I don't.
I don't have any idea why it is compiling correctly. a[ANYTHING] is of type comparable. Hopefully it is a small mistake. Even though I have reread this code over and over again.
I am writing a median of three quick sort algorithm and I just made my findMedian() method. I return type comparable, but
the compiler says I don't.
public static Comparable findMedian(Comparable[] a, int lo, int hi) { //MY CODE: Returns the median of lo, hi, and middle.
if ((less(a[lo],a[a.length/2])) && (less(a[hi],a[a.length/2])) && (less(a[lo],a[hi]))) {
return a[hi];
}
else if ((less(a[a.length/2],a[lo])) && (less(a[hi],a[lo])) && (less(a[hi], a[a.length/2]))) {
return a[a.length/2];
}
else if ((less(a[lo],a[hi])) && (less(a[a.length/2],a[hi])) && (less(a[lo],a[a.length/2]))) {
return a[lo];
}
}
I don't have any idea why it is compiling correctly. a[ANYTHING] is of type comparable. Hopefully it is a small mistake. Even though I have reread this code over and over again.