Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

quicksort my anus

Name: Anonymous 2011-12-04 23:44

http://alienryderflex.com/quicksort/

//  quickSort
//
//  This public-domain C implementation by Darel Rex Finley.
//
//  * Returns YES if sort was successful, or NO if the nested
//    pivots went too deep, in which case your array will have
//    been re-ordered, but probably not sorted correctly.
//
//  * This function assumes it is called with valid parameters.
//
//  * Example calls:
//    quickSort(&myArray[0],5); // sorts elements 0, 1, 2, 3, and 4
//    quickSort(&myArray[3],5); // sorts elements 3, 4, 5, 6, and 7

bool quickSort(int *arr, int elements) {

  #define  MAX_LEVELS  1000

  int  piv, beg[MAX_LEVELS], end[MAX_LEVELS], i=0, L, R ;

  beg[0]=0; end[0]=elements;
  while (i>=0) {
    L=beg[i]; R=end[i]-1;
    if (L<R) {
      piv=arr[L]; if (i==MAX_LEVELS-1) return NO;
      while (L<R) {
        while (arr[R]>=piv && L<R) R--; if (L<R) arr[L++]=arr[R];
        while (arr[L]<=piv && L<R) L++; if (L<R) arr[R--]=arr[L];
            }
      arr[L]=piv; beg[i+1]=L+1; end[i+1]=end[i]; end[i++]=L;
        } else {
      i--;
        }
    }
  return YES;
}

Name: Anonymous 2011-12-05 0:05


int ...,i = 0,...;
while(i >= 0){/* sort */}
return YES;


well designed

Name: Anonymous 2011-12-05 1:11

>>2
There's an i++ inside.

Also this doesn't look like quicksort but something else I've seen before (probably somewhere in Knuth's huge collection of sorting algorithms.)

Name: Anonymous 2011-12-05 1:46

>>3

It looks like quicksort implemented without recursion, where the state that is normally stored in the stack frames of the recursive function calls is instead stored in arrays.

Name: Anonymous 2014-03-11 13:57

I think shellsort is kind of cool.

Name: Anonymous 2014-03-11 15:31

fibbonazibuttsort

Don't change these.
Name: Email:
Entire Thread Thread List