2008-01-09

Quicksort in C#

Amazingly short in code and even intuitive if you are a bit into functional programming:

Func< intlist, intlist > Sort = 
xs =>
xs.Case(
() => xs,
(head,tail) => (Sort(tail.Where(x => x < head)))
.Concat
(Single(head))
.Concat
(Sort(tail.Where(x => x >= head)))
);
Taken from this presentation, also find more interesting features from C# 3.0 there.

Now argue with me, that some languages are not clunky compared to this!

1 comment:

Anonymous said...

would u be able to post a working version of this quicksort. where does Case come from?

thanks
David