I tried to implement a quicksort on arrays of int64_t
like this:
void quicksort (int64_t *array,size_t size) {
int64_t *split;
size_t i=0;
size_t j=size-1;
if (size>1) {
split=({
int64_t p=array[0];
do {
for (;array[i]<p;i++);
for (;array[j]>p;j--);
swap(array[i],array[j]);
} while (i<j);
swap(array[i],array[j]);
swap(array[j],array[size]);
&(array[j]);
})-1;
quicksort(array,j-1);
quicksort(split+1,size-j);
}
return;
}
Which is good, however, it enters into infinite recursion or infinite loop immediately after first partitioning pass. How can I solve this?