/** * krq.c * The K&R Quicksort. */ #include "sort.h" #include "swap.h" /** * kr_qsort: sort v[left]...v[right] into increasing alphabetical order. * Note: Renamed to avoid conflict with qsort in stlib.h. */ void sort (char *v[], int size) { int i, last; int left = 0; int right = size-1; /* If the array contains fewer than two elements, do nothing. */ if (left >= right) return; swap(v, left, (left + right)/2); last = left; for (i = left+1; i <= right; i++) if (strcmp (v[i], v[left]) < 0) swap(v, ++last, i); swap(v, left, last); sort (v, last); sort (v+last+1, size-last-1); } // qsort