Skip to content
Snippets Groups Projects
Commit 246ebd57 authored by Christopher Schankula's avatar Christopher Schankula :earth_africa:
Browse files

use quickselect for KDT (failing...)

parent d9107332
No related branches found
No related tags found
No related merge requests found
......@@ -119,7 +119,7 @@ public class KDT<KeyVal extends Comparable<KeyVal>> implements Serializable {
int axis = depth % getK();
int mid = (lo + hi) / 2;
MergeSort.sort(keyvals, lo, hi, axes.get(axis));
QuickSelect.median(keyvals, lo, hi, axes.get(axis));
KeyVal median = (KeyVal) keyvals[mid];
//TODO: fix size
......
......@@ -30,6 +30,16 @@ public class QuickSelect {
sort(a, 0, a.length - 1, a.length/2, gc);
}
/**
* Partially sorts a comparable array such that elements smaller than the median occur in
* the first half of the array, and elements larger than the median occur in the second half
* @param a Array of comparable items
* @param gc Lambda function to compare items
*/
public static <T> void median(Comparable<T>[] a, int lo, int hi, GeneralCompare<T> gc) {
sort(a, lo, hi, (hi - lo) / 2, gc);
}
/**
* Partially sorts a comparable array such that elements smaller than the kth largest element
* occur in the first half of the array, and larger elements occur in the second half
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment