Created
June 23, 2020 22:53
-
-
Save educartoons/fc300e42e20695680e3d2fbc491776db to your computer and use it in GitHub Desktop.
Implementation of Insertion Sort in C++
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
// numbers = array of numbers | |
// size = length of numbers | |
void insertionSort(int *numbers,int size){ | |
int i, j, key; | |
for (j=1; j<size; j++) { | |
key = numbers[j]; | |
i = j - 1; | |
while(i>=0 and numbers[i]>key){ | |
numbers[i+1] = numbers[i]; | |
i = i - 1; | |
} | |
numbers[i+1] = key; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment