Created
June 2, 2013 16:09
-
-
Save serkansendur/5693960 to your computer and use it in GitHub Desktop.
c# insertion sort
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
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