Pretty Quick Sort With C# 3.0

January 29, 2009

Jafar Husain writes about the prettiness of F#'s type inference, but what I really liked in his post was his C# 3.0 implementation for Quick Sort: 1 public static IEnumerable<T> QuickSort<T>(this IEnumerable<T> list) 2 where T : IComparable 3 { 4 if (!list.Any()) 5 { 6 return Enumerable.Empty<T>(); 7 } 8 var pivot = list.First(); 9 var smaller = list.Where(item => item.CompareTo(pivot) <= 0).QuickSort(); 10 var...
tags:
6 comments