Partitioning and pivot selection is all there is to quick sort so by all means watch it execute. That is what you are asking us to show.
The wysiwyg function will dump the array as-is and the current pivot when you first select the pivot, whenever there is a swap, and when the partition finishes. That way you can see your partitioning. Debugging would be able to show you this as well.
Code:
#include <stdio.h>
void wysiwyg(int v[], int left, int right, int pivot);
void wysiwyg(int v[], int left, int right, int pivot) {
int i;
fputs("( ", stdout);
for (i = left; i < (right + 1); i++) {
printf("%d, ", v[i]);
}
printf(") pivot=%d... \n", pivot);
fflush(stdout);
}
/* qsort: sort v[left]...v[right] into increasing order */
void qsort(int v[], int left, int right) {
int i,
last;
/* void swap(int v[], int i, int j); a misplaced prototype? */
if (left >= right) /* do nothing if array contains */
return; /* fewer than two elements */
swap(v, left, (left + right) / 2); /* move partition elem */
last = left; /* to v[0] */
wysiwyg(v, left, right, last);
for (i = left + 1; i <= right; i++) /* partition */
if (v[i] < v[left]) {
swap(v, ++last, i);
wysiwyg(v, left, right, last);
}
swap(v, left, last); /* restore partition elem */
wysiwyg(v, left, right, last);
qsort(v, left, last - 1);
qsort(v, last + 1, right);
}
Use comments and you have a "quiet" quick sort again.