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

  1. Xref: sparky comp.os.os2.programmer:6457 comp.os.os2.apps:8318
  2. Newsgroups: comp.os.os2.programmer,comp.os.os2.apps
  3. 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
  4. From: jurlwin@gandalf.UMCS.Maine.EDU (Jeff Urlwin)
  5. Subject: Re: qsort() in gcc does not do indirect sorting?
  6. Message-ID: <1992Nov15.230107.29374@gandalf.UMCS.Maine.EDU>
  7. Organization: University of Maine, Department of Computer Science
  8. References: <1e3ejjINNdf4@pollux.usc.edu> <1e44n6INN49u@iskut.ucs.ubc.ca>
  9. Date: Sun, 15 Nov 1992 23:01:07 GMT
  10. Lines: 36
  11.  
  12. In article <1e44n6INN49u@iskut.ucs.ubc.ca> ochealth@unixg.ubc.ca (ochealth) writes:
  13. >In article <1e3ejjINNdf4@pollux.usc.edu> ckhung@pollux.usc.edu (Chao-Kuei Hung) writes:
  14. >:
  15. >:int cmp(const int *i, const int *j)
  16. >:{
  17. >:    return(data[*i].x < data[*j].x ? -1 : 1);
  18. >:}
  19. >
  20. >
  21. >BZZZZZT! How will cmp() ever show that data[*i].x == data[*j].x??
  22. >Your cmp() can never return 0 to show that the two are equal. Perhaps
  23. >this worked on other platforms, because that particular sort didn't
  24. >matter if  a==b. I think the sort is getting into an infinite loop
  25. >because of this.
  26. >
  27. >This works in EMX/GCC:
  28. >
  29. >int
  30. >cmp (const int * i, const int * j)
  31. >{
  32. >    if (data[*i].x == data[*j].x)
  33. >      return 0;
  34. >    if (data[*i]].x < data[*j].x)
  35. >      return -1;
  36. >    return 1;
  37. >}
  38.  
  39. Better yet, 
  40.   return (data[*j].x - data[*i].x);
  41.  
  42. Jeff
  43.  
  44. -- 
  45. --------------------------------------
  46. jurlwin@gandalf.umcs.maine.edu
  47.  
  48.