in: haskell.org
3.1 Quicksort in Haskell
qsort [] = []
qsort (x:xs) =
qsort (filter (< x) xs) ++ [x] ++
qsort (filter (>= x) xs)
NOTE: I've broken into 4 lines because of my blog template limitations.
void qsort(int a[], int lo, int hi) {
{
int h, l, p, t;
if (lo < hi) {
l = lo;
h = hi;
p = a[hi];
do {
while ((l < h) && (a[l] <= p))
l = l+1;
while ((h > l) && (a[h] >= p))
h = h-1;
if (l < h) {
t = a[l];
a[l] = a[h];
a[h] = t;
}
} while (l < h);
t = a[l];
a[l] = a[hi];
a[hi] = t;
qsort( a, lo, l-1 );
qsort( a, l+1, hi );
}
}
Oops, is language evolution betting on the wrong branch?
1 comment:
A very good interview with Simon Peyton Jones by Port25 is available at: http://port25.technet.com/archive/2007/09/26/haskell-in-the-hallway-sam-interviews-simon-peyton-jones.aspx
Post a Comment