Skip to content

Instantly share code, notes, and snippets.

@educartoons
Created June 23, 2020 22:53
Show Gist options
  • Save educartoons/fc300e42e20695680e3d2fbc491776db to your computer and use it in GitHub Desktop.
Save educartoons/fc300e42e20695680e3d2fbc491776db to your computer and use it in GitHub Desktop.
Implementation of Insertion Sort in C++
// 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