Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

I return type Comparable, but java says I did not.

$
0
0
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.

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.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>