Skip to content

Instantly share code, notes, and snippets.

@otf
Created August 27, 2013 10:16
Show Gist options
  • Save otf/6351849 to your computer and use it in GitHub Desktop.
Save otf/6351849 to your computer and use it in GitHub Desktop.
public static int[] QuickSort(int[] arr)
{
if (!arr.Any()) return new int[] { };
var p = arr.First();
var xs = arr.Skip(1);
var lesser = xs.Where(x => x < p).ToArray();
var greater = xs.Where(x => x >= p).ToArray();
return (QuickSort(lesser).Concat(new[] { p }).Concat(QuickSort(greater))).ToArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment