From: alan@nabeth.cxo.dec.com (Alan Rollow - Dr. File System's Home for Wayward Inodes.)
Subject: Re: Qsort problem in DEC C
Date: 6 Feb 1995 23:14:06 GMT [thread overview]
Message-ID: <3h6afu$fsn@nntpd2.cxo.dec.com> (raw)
In-Reply-To: lloyd-dr-0302950907550001@149.252.239.58
In article <lloyd-dr-0302950907550001@149.252.239.58>, lloyd-dr@nlvvax.llnl.egg.nv.doe.gov (David Lloyd) writes:
> [ A common qsort compare routine problem. ]
>
>int compare (int *a, int *b)
>{
> if (a < b) return(-1);
> if (a == b) return(0);
> if (a > b) return(1);
>}
>
Ignoreing the strange message about the arguments, they really
are pointers being passed. Your code is comparing the value
of the pointers, not the integers they to which they point.
Useful code would look like:
if( *a < *b )
return -1 ;
else if( *a == *b )
return 0 ;
else
return 1 ;
--
Alan Rollow alan@nabeth.cxo.dec.com
prev parent reply other threads:[~1995-02-06 23:14 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
1995-02-03 17:05 Qsort problem in DEC C David Lloyd
1995-02-03 18:59 ` David Jones
1995-02-03 19:33 ` John Buehler
1995-02-06 23:14 ` Alan Rollow - Dr. File System's Home for Wayward Inodes. [this message]
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox