Skip to content

Instantly share code, notes, and snippets.

@danielcrenna
Created December 18, 2012 04:35
Show Gist options
  • Save danielcrenna/4325033 to your computer and use it in GitHub Desktop.
Save danielcrenna/4325033 to your computer and use it in GitHub Desktop.
An implementation of insertion sort in C#.
using System.Collections.Generic;
public class InsertionSort
{
public void Sort<T>(IList<T> items)
{
for (var i = 1; i < items.Count; i++)
{
int j;
var left = items[i];
var code = left.GetHashCode();
for(j = i - 1; j >= 0 && (items[j].GetHashCode() > code); j--)
{
items[j + 1] = items[j];
}
items[j + 1] = left;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment