home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 6365 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.3 KB

  1. Path: ccshst05.cs.uoguelph.ca!ccshst01!jsadler
  2. From: jsadler@uoguelph.ca (J. Sadler)
  3. Newsgroups: comp.lang.c,comp.sys.amiga.programmer
  4. Subject: Re: MY SORT DOESN'T QUICK!
  5. Followup-To: comp.lang.c,comp.sys.amiga.programmer
  6. Date: 27 Mar 1996 03:34:53 GMT
  7. Organization: University of Guelph
  8. Message-ID: <4jad0t$2sg@ccshst05.cs.uoguelph.ca>
  9. References: <2082.6659T1310T2974@xs4all.nl>
  10. NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
  11. X-Newsreader: TIN [version 1.2 PL2]
  12.  
  13. (oops erased the subject, hope i got all mucked up posts cleaned up)
  14.  
  15. : try this one (needs to be translated to right vars):
  16. : your's misses the do/while, the if on the recursion looking at it quick.
  17. : also i have 1 mid/pivot per call while u differ yours in a call.
  18. : (BTW mines based on c standard, so it's a bit different struct.)
  19.  
  20. : a is the array, start is the start, end is the end.
  21.  
  22. : void quicksort( int a[],int,start,int end )
  23. : {
  24. :    int low, high, pivot;
  25.  
  26. :    low=start;
  27. :    high=end;
  28. :    pivot=a[end];
  29.  
  30. :    do {
  31. :        while ((low<high) && (a[low]<=pivot))
  32. :            ++low;
  33. :        while ((high>low) && (a[high]>=pivot))
  34. :        --high;
  35. :        if (low<high)
  36. :       /* do the swap */
  37. :    } while (low<high);
  38.  
  39. :    /* do the swap */
  40.  
  41. :    if (low-1>start)
  42. :            quicksort(a,start,low-1);
  43. :    if (end>low+1)
  44. :         quicksort(a,low+1,end);
  45. :    return;
  46. : }
  47.