home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.os.os2.programmer:6457 comp.os.os2.apps:8318
- Newsgroups: comp.os.os2.programmer,comp.os.os2.apps
- Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!news.bbn.com!noc.near.net!mars.caps.maine.edu!gandalf!jurlwin
- From: jurlwin@gandalf.UMCS.Maine.EDU (Jeff Urlwin)
- Subject: Re: qsort() in gcc does not do indirect sorting?
- Message-ID: <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>
- Organization: University of Maine, Department of Computer Science
- References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca>
- Date: Sun, 15 Nov 1992 23:01:07 GMT
- Lines: 36
-
- 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);
-
- Jeff
-
- --
- --------------------------------------
- jurlwin@gandalf.umcs.maine.edu
-
-