qsort(), bsearch(), and rude comparison functions

Felix Lee flee at guardian.cs.psu.edu
Wed Oct 10 18:05:48 AEST 1990


I spoke hastily.  Even if comparison is random, any reasonable sorting
algorithm "makes progress" and will do no more than the worst-case
number of comparisons.

qsort() in 4.3 BSD however will have a decent chance of running past
the bounds of the array in its final insertion sort pass.  Here's a
pathological comparator that guarantees this behavior:
	int cmp(a, b) char * a; char * b;
	{ return b - a; }
--
Felix Lee	flee at cs.psu.edu



More information about the Comp.std.c mailing list