Last active
February 22, 2018 16:10
-
-
Save jp26jp/05f61b21e90db4c0212a86a605d773ca to your computer and use it in GitHub Desktop.
Insertion sort algorithm
This file contains hidden or 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
void insertionSort(int[] array) | |
{ | |
for (int i = 1; i < array.length; i++) | |
{ | |
int index = i, indexValue = array[index]; | |
while (index > 0 && array[index - 1] > indexValue) array[index] = array[--index]; | |
array[index] = indexValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment