Skip to content

Instantly share code, notes, and snippets.

@serkansendur
Created June 2, 2013 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serkansendur/5693960 to your computer and use it in GitHub Desktop.
Save serkansendur/5693960 to your computer and use it in GitHub Desktop.
c# insertion sort
static void InsertSort<T>(T[] array) where T : IComparable<T>
{
int i, j;
for (i = 1; i < array.Length; i++)
{
T value = array[i];
j = i - 1;
while ((j >= 0) && (array[j].CompareTo(value) > 0))
{
array[j + 1] = array[j];
j--;
}
array[j + 1] = value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment