Your quicksort
method returns the sorted array but you don't assign it. Change it to
arraylist = quicksort(arraylist);
and it works just fine.
It is true that you can modify the arraylist in your quicksort method, so there would be no need to assign it, but that's not what you're doing. All you do is delete the pivot and then return a new list created by concatenate
. That's why in your algorithm you get the original list with 7
missing.
If you don't want to assign the list again, you need to do something like:
private static void quicksort(List<Integer> place) {
if (place.size() <= 1)
return;
int median=place.size()/2;
int pivot=place.get(median);
place.remove(median);
List<Integer> place2 = new ArrayList<>();
List<Integer> place3 = new ArrayList<>();
Iterator<Integer> it = place.iterator();
while (it.hasNext()) {
int i = it.next();
if (i < pivot) {
place2.add(i);
} else {
place3.add(i);
}
it.remove();
}
quicksort(place2);
quicksort(place3);
for (Integer i : place2) {
place.add(i);
}
place.add(pivot);
for (Integer i : place3) {
place.add(i);
}
}