| quicksort.c - Funktionen do_partitioning der opdeler tabellens elementer op i store og små. | Lektion 8 - slide 26 : 27 Program 1 |
/* Do a partitioning of a, and return the partitioning
points in *point_left and *point_right */
void do_partitioning(element a[], index from, index to,
index *point_left, index *point_right){
index i,j;
element partitioning_el;
i = from - 1; j = to + 1;
partitioning_el = a[from];
do{
do {i++;} while (a[i] < partitioning_el);
do {j--;} while (a[j] > partitioning_el);
if (i < j) swap(&a[i],&a[j]);
} while (i < j);
if (i > j) {
*point_left = j; *point_right = i;}
else {
*point_left = j-1; *point_right = i+1;}
}