Last active
June 10, 2020 18:12
-
-
Save takint/86c551072b30a9dc3ae10b69d02b6baa to your computer and use it in GitHub Desktop.
Insertion an element within the array for 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 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