home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / os2 / programm / 6458 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  2.0 KB

  1. Xref: sparky comp.os.os2.programmer:6458 comp.os.os2.apps:8320
  2. Path: sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!destroyer!cs.ubc.ca!unixg.ubc.ca!ochealth
  3. From: ochealth@unixg.ubc.ca (ochealth)
  4. Newsgroups: comp.os.os2.programmer,comp.os.os2.apps
  5. Subject: Re: qsort() in gcc does not do indirect sorting?
  6. Message-ID: <1e6q6dINN7cp@iskut.ucs.ubc.ca>
  7. Date: 16 Nov 92 00:32:13 GMT
  8. Article-I.D.: iskut.1e6q6dINN7cp
  9. References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca> <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>
  10. Organization: University of British Columbia, Vancouver, B.C., Canada
  11. Lines: 49
  12. NNTP-Posting-Host: unixg.ubc.ca
  13.  
  14. In article <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU> jurlwin@gandalf.UMCS.Maine.EDU (Jeff Urlwin) writes:
  15. :In article <1e44n6INN49u@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
  16. :>In article <1e3ejjINNdf4@pollux.usc.edu> ckhung@pollux.usc.edu (Chao-Kuei Hung) writes:
  17. :>:
  18. :>:int cmp(const int *i, const int *j)
  19. :>:{
  20. :>:    return(data[*i].x < data[*j].x ? -1 : 1);
  21. :>:}
  22. :>
  23. :>
  24. :>BZZZZZT! How will cmp() ever show that data[*i].x == data[*j].x??
  25. :>Your cmp() can never return 0 to show that the two are equal. Perhaps
  26. :>this worked on other platforms, because that particular sort didn't
  27. :>matter if  a==b. I think the sort is getting into an infinite loop
  28. :>because of this.
  29. :>
  30. :>This works in EMX/GCC:
  31. :>
  32. :>int
  33. :>cmp (const int * i, const int * j)
  34. :>{
  35. :>    if (data[*i].x == data[*j].x)
  36. :>      return 0;
  37. :>    if (data[*i]].x < data[*j].x)
  38. :>      return -1;
  39. :>    return 1;
  40. :>}
  41. :
  42. :Better yet, 
  43. :  return (data[*j].x - data[*i].x);
  44.  
  45.  
  46. I know, but my ANSI reference says compare() should only return -1, 0, or 1.
  47. for < = >, but maybe that's wrong.
  48.  
  49. :
  50. :Jeff
  51. :
  52. :-- 
  53. :--------------------------------------
  54. :jurlwin@gandalf.umcs.maine.edu
  55. :
  56.  
  57.  
  58. -- 
  59. ______________________________________________________________________________
  60. jpm: ochealth@unixg.ubc.ca         
  61.                             Happily using OS/2 2.0 because MS Windows isNT ___
  62.                                                       Insert VapourFeature ^^^
  63.