Created
December 18, 2012 04:35
-
-
Save danielcrenna/4325033 to your computer and use it in GitHub Desktop.
An implementation of insertion sort in C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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