Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Java by mr5 ( 10 years ago )
DataPoint points[] = new DataPoint[50];
for(int i = 0;i < points.length; ++i) {
 points[i] = new DataPoint(i, i);
}

Arrays.sort(points, new Comparator<DataPoint>() {
 @Override
 public int compare(DataPoint lhs, DataPoint rhs) {
  return (int) (lhs.getY() - rhs.getY());
 }
});

int halfLength = points.length / 2;
DataPoint[] p1 = new DataPoint[halfLength];
for(int i = 0;i < halfLength; ++i) {
 DataPoint p = points[i];
 p1[i] = new DataPoint(p.getX(), p.getY());
}
DataPoint[] p2 = new DataPoint[halfLength];
for(int i = halfLength;i < points.length; ++i) {
 DataPoint p = points[i];
 p2[i - halfLength] = new DataPoint(p.getX(), p.getY());
}

Arrays.sort(p2, new Comparator<DataPoint>() {
 @Override
 public int compare(DataPoint lhs, DataPoint rhs) {
  return (int) (rhs.getY() - lhs.getY());
 }
});

points = arrayConcat(p1, p2);

 

Revise this Paste

Your Name: Code Language: