qsort - part of an array

BAILEY CHRISTOPHER R baileyc at boulder.Colorado.EDU
Tue Apr 10 17:55:25 AEST 1990

I'm not sure how to use qsort.  I have an array, where only the end of
it needs to be sorted (say the last 5 elements).  The part that confuses
me the most is the comparand.  So, say my array is mapping[10] and I need
to sort all the elements from mapping[4] to mapping [9].  How do I do this
using qsort?  Assumming that qsort is called like this:

	qsort(base, num, width, (compare)());
where: 	base = start of target array
		num = array size in elements
		width = element size in bytes
		compare function

So, I would assume that my base would be mapping[4], that num would be
10, and that width would be sizeof(int), but what about compare?

In my case, if mapping is [10], then the highest number that can be stored
in this array is 9, only the numbers 0 - 9 could be used in this array, and
each one only once.  so mapping could look like: 1,3,5,9,8,2,7,6,0,4.

How do I use compare?  All the examples I've seen the compare doesn't make
sense to me.  Thanks...
Chris Bailey :: baileyc at tramp.Colorado.EDU
One Agro Mountain Biker - Dialed in for ultra gonzo badness!
"No his mind is not for rent, to any god or government" - RUSH
Member of Team Buck Naked of Buckingham Palace

More information about the Comp.lang.c mailing list