I'm currently working on QuickSort in Java, and I've successfully sorted the list for the first iteration. Nonetheless, my recursion implementation is not doing what I want. What can be the reason for that?
The list is [11, 4, 53, 65, 44, 23, 202, 37, 1]
...
quickSort(list, 0, list.size() - 1);
...
public static List<Integer> quickSort(List<Integer> l1, int from, int to) {
if (l1.size() < 2)
return l1;
int pivot = l1.get(to);
int counterLastSwapPos = 0;
int counter = from;
while (counter < l1.indexOf(pivot)) {
if (l1.get(counter) >= pivot)
counter++;
else {
int temp = l1.get(counter);
l1.set(counter, l1.get(counterLastSwapPos));
l1.set(counterLastSwapPos, temp);
counterLastSwapPos++;
}
System.out.println(l1);
}
quickSort(l1, 0, l1.indexOf(pivot));
quickSort(l1, l1.indexOf(pivot) + 1, l1.size());
return l1;
}
fromandto, rather than putting it at the end (to)quickSort(l1, 0, l1.indexOf(pivot)); quickSort(l1, l1.indexOf(pivot) + 1, l1.size());If so, do thisquickSort(l1, from, l1.indexOf(pivot)); quickSort(l1, l1.indexOf(pivot) + 1, to);