Skip to content

Instantly share code, notes, and snippets.

@takint
Last active June 10, 2020 18:12
Show Gist options
  • Save takint/86c551072b30a9dc3ae10b69d02b6baa to your computer and use it in GitHub Desktop.
Save takint/86c551072b30a9dc3ae10b69d02b6baa to your computer and use it in GitHub Desktop.
Insertion an element within the array for insertion sort
static void InsertionSort(int a[])
{
for(int i = 1; i < a.Length; i++)
{
Insertion(a, i-1, a[i]);
}
}
static void Insertion(int[] a, int rightIndex, int value)
{
int i = rightIndex;
for(; i >= 0 && a[i] > value; i--)
{
a[i+1] = a[i];
}
a[i+1] = value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment