/* file: functions.c Usage: Used together with qsort.c */ void qsort(v, left, right) int v[], left, right; { int i, last; void swap(); if (left >= right) /*do nothing if the subarray contains less than 2 elements*/ return; swap(&v[left], &v[(left + right)/2]); /*move the partition element to v[0]*/ last = left; for (i=left+1; i<=right; i++) /*partition the array*/ if (v[i] < v[left]) swap(&v[++last], &v[i]); swap(&v[left], &v[last]); /*restore the partition element*/ qsort(v, left, last-1); qsort(v, last+1, right); } void swap(i, j) int *i, *j; { int temp; temp=*i; *i=*j; *j=temp; }