/** * qs.c * A modified version of the K&R Quicksort. */ #include #include #include "sort.h" #include "swap.h" /** * qs: sort v[0]...v[size-1] into increasing alphabetical order. */ void sort (char *v[], int size) { int i, last; /* If the array contains fewer than two elements, do nothing. */ if (size <= 1) return; swap(v, 0, size/2); last = 0; for (i = 1; i < size; i++) if (strcmp (v[i], v[0]) < 0) swap(v, ++last, i); swap(v, 0, last); sort (v, last); sort (v+last+1, size-last-1); } // kr_qsort