the <
and >
in your code is reverse in partition()
as @Dietmar Kühl mentioned,by change them,it works correctly.
besides,my suggestion is to use a normal partition()
of quicksort as follow, for whose two index of which move in the same direction and one of them never surpasses another. It is not easy to make anyone confused.
int partition(int *input, int p, int r) {
int pivot,i,j,tmp;
pivot = input[r];
i = p-1;
for (j=p;j<=r-1;j++) {
if (input[j]>= pivot) {
i++;
tmp = input[i];
input[i] = input[j];
input[j] = tmp;
}
}
tmp = input[i+1];
input[i+1] = input[r];
input[r] = tmp;
return i+1;
}