Hallo!
Habe eine ArrayList, in der Punkte abgespeichert sind (x- und y- Koordinaten).
Diese ArrayList möchte ich mittels Qicksort aufsteigend sortieren. Das habe ich bisher schon:
Mit diesem Programm wird bisher jedoch nur die x- Koordinate allein richtig sortiert. Mit der .get()- Methode kann ich nicht auf das vollständige Punktobjekt zugreifen. Ich erhalte eine Fehlermeldung Can't match Point to int.
Kann mir jemand helfen, wie ich das komplette Punktobjekt sortieren kann?
Danke schonmal!
Viele Grüße,
kwonilchang
Habe eine ArrayList, in der Punkte abgespeichert sind (x- und y- Koordinaten).
Diese ArrayList möchte ich mittels Qicksort aufsteigend sortieren. Das habe ich bisher schon:
Code:
void quickSort(ArrayList <Point> points, int low, int high) {
// select middle element to split list
int pivot = points.get((low+high)/2).x;
// define markers i and j
int i = low;
int j = high;
// split array
while (i<=j) {
while (points.get(i).x < pivot) i++;
while (points.get(j).x > pivot) j--;
if (i<=j) {
int tmp = points.get(i).x;
points.get(i).x = points.get (j).x;
points.get(j).x = tmp;
i++;
j--;
}
} // the pivot element should now be in the right position
// recursion: sort the lists left and right of the pivot
if (j > low) quickSort(points, low, j);
if (i < high) quickSort(points, i, high);
}
Mit diesem Programm wird bisher jedoch nur die x- Koordinate allein richtig sortiert. Mit der .get()- Methode kann ich nicht auf das vollständige Punktobjekt zugreifen. Ich erhalte eine Fehlermeldung Can't match Point to int.
Kann mir jemand helfen, wie ich das komplette Punktobjekt sortieren kann?
Danke schonmal!
Viele Grüße,
kwonilchang