Quicksort algorithm displaying strange behaviour
Code :
public void quickSort(int[] items, int left, int right){
System.out.println(count);
count++;
int pivot = (left + right) / 2;
int tmp;
int i = left, j = right;
while(items[i] <= items[pivot] && items[j] >= items[pivot]){
while(items[i] < items[j]){
i++;
j--;
}
tmp = items[i];
items[i] = items[j];
items[j] = tmp;
}
if((left + pivot) > 1){
quickSort(items, left, pivot);
}
if((right + pivot) > 1){
quickSort(items, pivot, right);
}
}
I have set up a counter to count how many times this method recurses. It gets to 4 and then nothing happens - the program doesn't exit but nothing else is printed and it doesn't finish sorting.