Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created October 8, 2011 03:43
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 renatoargh/1271822 to your computer and use it in GitHub Desktop.
Save renatoargh/1271822 to your computer and use it in GitHub Desktop.
InsertionSort
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