LINQ QuickSort in C#
By andre
This is most certainly not the recommended way of implementing QuickSort, it assumes there are no duplicates, but it should work:
private IList<int> sort(IList<int> a)
{
if (a.Count <= 1)
return a;
return sort(a.Where(x => x < a[0]).ToList()).Union(new List<int> { a[0] }).Union(sort(a.Where(x => x > a[0]).ToList())).ToList();
}
It’s a nice demonstration of how C# is getting closer to resemble a proper lambda-oriented functional language.