Skip to content

Instantly share code, notes, and snippets.

@renatoargh
Created October 9, 2011 07:42
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/1273410 to your computer and use it in GitHub Desktop.
Save renatoargh/1273410 to your computer and use it in GitHub Desktop.
InsertionSort-Analizado
public void InsertionSort(List<Int32> elements, Boolean ascending = true)
{ //CUSTO EXECUÇÕES
for (Int32 j = 1; j < elements.Count; j++) //c1 n
{
Int32 key = elements[j]; //c2 n - 1
Int32 i = j - 1; //c3 n - 1
while (i >= 0 && (elements[i] > key) == ascending) //c4 somatorio[j = 1 -> n] tj
{
elements[i + 1] = elements[i]; //c5 somatorio[j = 1 -> n] tj - 1
i--; //c6 somatorio[j = 1 -> n] tj - 1
}
elements[i + 1] = key; //c7 n - 1
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment