I know this isn't really a bug-testing place, but I've been trying to spot my error in my java quicksort for hours, and I can't see it, so if anyone can point it out to me I'd be very very grateful.
Here's example:
public class QuickSort {
public static int partition(int[] a, int start, int end) {
int piv = a[end];
int iLeft = start;
int iRight = end;
while (iLeft < iRight) {
while (a[iLeft] < piv) {
iLeft++;
}
while (a[iRight] >= piv) {
iRight--;
if (iRight == iLeft) {
break;
}
}
if (iLeft < iRight) {
int val = a[iLeft];
a[iLeft] = a[iRight];
a[iRight] = val;
}
}
return iRight;
}
public static int[] Sort(int[] a, int start, int end) {
if (a.length < 2) {
return a;
} else {
int Next_Mid = partition(a, start, end);
Sort(a, start, Next_Mid);
Sort(a, Next_Mid + 1, end);
return a;
}
}
public static void main(String[] args) {
int[] c = new int[] { 1, 10, 2, 9, 3, 8, 3, 7, 4, 6, 5 };
Sort(c, 0, c.length - 1);
}
}