E D R S I H C RSS
ID
Password
Join
You will hear good news from one you thought unfriendly to you.

FrontPage QuickSort

Difference between r1.2 and the current

@@ -1,4 +1,30 @@
{{{import random
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):

@@ -8,5 +34,5 @@
pivot = random.choice(list)
list.remove(pivot)



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.4175 sec