home *** CD-ROM | disk | FTP | other *** search
- Path: ccshst05.cs.uoguelph.ca!ccshst01!jsadler
- From: jsadler@uoguelph.ca (J. Sadler)
- Newsgroups: comp.lang.c,comp.sys.amiga.programmer
- Subject: Re: MY SORT DOESN'T QUICK!
- Followup-To: comp.lang.c,comp.sys.amiga.programmer
- Date: 27 Mar 1996 03:34:53 GMT
- Organization: University of Guelph
- Message-ID: <4jad0t$2sg@ccshst05.cs.uoguelph.ca>
- References: <2082.6659T1310T2974@xs4all.nl>
- NNTP-Posting-Host: ccshst01.cs.uoguelph.ca
- X-Newsreader: TIN [version 1.2 PL2]
-
- (oops erased the subject, hope i got all mucked up posts cleaned up)
-
- : try this one (needs to be translated to right vars):
- : your's misses the do/while, the if on the recursion looking at it quick.
- : also i have 1 mid/pivot per call while u differ yours in a call.
- : (BTW mines based on c standard, so it's a bit different struct.)
-
- : a is the array, start is the start, end is the end.
-
- : void quicksort( int a[],int,start,int end )
- : {
- : int low, high, pivot;
-
- : low=start;
- : high=end;
- : pivot=a[end];
-
- : do {
- : while ((low<high) && (a[low]<=pivot))
- : ++low;
- : while ((high>low) && (a[high]>=pivot))
- : --high;
- : if (low<high)
- : /* do the swap */
- : } while (low<high);
-
- : /* do the swap */
-
- : if (low-1>start)
- : quicksort(a,start,low-1);
- : if (end>low+1)
- : quicksort(a,low+1,end);
- : return;
- : }
-