Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!elroy.jpl.nasa.gov!ncar!boulder!tramp!baileyc From: baileyc@boulder.Colorado.EDU (BAILEY CHRISTOPHER R) Newsgroups: comp.lang.c Subject: qsort - part of an array Keywords: qsort, array Message-ID: <19496@boulder.Colorado.EDU> Date: 10 Apr 90 07:55:25 GMT Sender: news@boulder.Colorado.EDU Reply-To: baileyc@tramp.Colorado.EDU (BAILEY CHRISTOPHER R) Distribution: usa Organization: University of Colorado, Boulder Lines: 25 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@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