Created
October 8, 2011 03:43
-
-
Save renatoargh/1271822 to your computer and use it in GitHub Desktop.
InsertionSort
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
public void InsertionSort(List<Int32> elements, Boolean ascending = true) | |
{ | |
for (Int32 j = 1; j < elements.Count; j++) | |
{ | |
Int32 key = elements[j]; | |
Int32 i = j - 1; | |
while (i >= 0 && (elements[i] > key) == ascending) | |
{ | |
elements[i + 1] = elements[i]; | |
i--; | |
} | |
elements[i + 1] = key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment