Sorting algorithms/Quicksort: Difference between revisions

add C, array of integers
(-> IDL)
(add C, array of integers)
Line 3:
 
In this task, the goal is to sort an array of elements using the [http://en.wikipedia.org/wiki/Quicksort Quicksort] algorithm. The elements must have a total order and the index of the array can be of any discrete type. For languages where this is not possible, sort an array of integers.
 
=={{header:C}}==
void quick(int *left, int *right)
{
if (right > left) {
int pivot = left[(right-left)/2];
int *r = right, *l = left;
do {
while (*l < pivot) l++;
while (*r > pivot) r--;
if (l <= r) {
int t = *l;
*l++ = *r;
*r-- = t;
}
} while (l <= r);
quick(left, r);
quick(l, right);
}
}
void sort(int *array, int length)
{
quick(array, array+length-1);
}
 
==[[IDL]]==
Anonymous user