E D R S I H C RSS
ID
Password
Join
You have literary talent that you should take pains to develop.

FrontPage QuickSort

C
void qsort(int start, int end, int arr[]) {
    int s = start;
    int e = end;
    int p = answer[(start+end)/2];

    while ( s <= e ) {
      while ( arr[s] < p ) s++;
      while ( arr[e] > p ) e--;

      if ( s <= e ) {
          int t = arr[s];
          arr[s] = arr[e];
          arr[e] = t;
          s++;
          e--;
      }
    }

    if ( start < e ) qsort(start, e, arr);
    if ( s < end   ) qsort(s,   end, arr);
}

Python
import random 

def qsort(list):
    
    if len(list) <= 1:
        return list

    pivot = random.choice(list)
    list.remove(pivot)
    
    return qsort([it for it in list if it < pivot]) + [pivot] + qsort([it for it in list if it >= pivot])
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2016-06-30 01:38:17
Processing time 0.0243 sec