Article View: comp.os.os2.programmer
Article #2954Re: qsort() in gcc does not do indirect sorting?
From: ochealth
Date: Mon, 16 Nov 1992 00:32
Date: Mon, 16 Nov 1992 00:32
49 lines
2067 bytes
2067 bytes
In article <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU> jurlwin@gandalf.UMCS.Maine.EDU (Jeff Urlwin) writes:
:In article <1e44n6INN49u@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
:>In article <1e3ejjINNdf4@pollux.usc.edu> ckhung@pollux.usc.edu (Chao-Kuei Hung) writes:
:>:
:>:int cmp(const int *i, const int *j)
:>:{
:>: return(data[*i].x < data[*j].x ? -1 : 1);
:>:}
:>
:>
:>BZZZZZT! How will cmp() ever show that data[*i].x == data[*j].x??
:>Your cmp() can never return 0 to show that the two are equal. Perhaps
:>this worked on other platforms, because that particular sort didn't
:>matter if a==b. I think the sort is getting into an infinite loop
:>because of this.
:>
:>This works in EMX/GCC:
:>
:>int
:>cmp (const int * i, const int * j)
:>{
:> if (data[*i].x == data[*j].x)
:> return 0;
:> if (data[*i]].x < data[*j].x)
:> return -1;
:> return 1;
:>}
:
:Better yet,
: return (data[*j].x - data[*i].x);
I know, but my ANSI reference says compare() should only return -1, 0, or 1.
for < = >, but maybe that's wrong.
:
:Jeff
:
:--
:--------------------------------------
:jurlwin@gandalf.umcs.maine.edu
:
--
______________________________________________________________________________
jpm: ochealth@unixg.ubc.ca
Happily using OS/2 2.0 because MS Windows isNT ___
Insert VapourFeature ^^^
Technical Details
Message-ID:
<1e6q6dINN7cp@iskut.ucs.ubc.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!unixg.ubc.ca!ochealthReferences:
<1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca> <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!unixg.ubc.ca!ochealth From: ochealth@unixg.ubc.ca (ochealth) Newsgroups: comp.os.os2.programmer,comp.os.os2.apps Subject: Re: qsort() in gcc does not do indirect sorting? Message-ID: <1e6q6dINN7cp@iskut.ucs.ubc.ca> Date: 16 Nov 92 00:32:13 GMT Article-I.D.: iskut.1e6q6dINN7cp References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca> <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU> Organization: University of British Columbia, Vancouver, B.C., Canada Lines: 49 NNTP-Posting-Host: unixg.ubc.ca