Created
January 11, 2018 01:22
-
-
Save nerohoop/d4c2024eb0b4e1232e88a88dea4b8f75 to your computer and use it in GitHub Desktop.
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
void Sort::insertionSort(int *arr, int size) { | |
int key = 0; | |
for (int i=1; i < size; i++) { | |
key = arr[i]; | |
// Move elements of arr[0..i-1], that are greater than key, | |
// to one position ahead of their current position. | |
int j = i-1; | |
while (j>=0 && arr[j] > key) { | |
arr[j+1] = arr[j]; | |
j = j-1; | |
} | |
arr[j+1] = key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment