Skip to content

Instantly share code, notes, and snippets.

@YassineBajdou
Created November 8, 2018 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YassineBajdou/df3cd8e47a111a83076202b67f6db4a4 to your computer and use it in GitHub Desktop.
Save YassineBajdou/df3cd8e47a111a83076202b67f6db4a4 to your computer and use it in GitHub Desktop.
void insertion_sort ( int A[ ] , int n)
{
for( int i = 0 ;i < n ; i++ ) {
/*storing current element whose left side is checked for its
correct position .*/
int temp = A[ i ];
int j = i;
/* check whether the adjacent element in left side is greater or
less than the current element. */
while( j > 0 && temp < A[ j -1]) {
// moving the left side element to one position forward.
A[ j ] = A[ j-1];
j= j - 1;
}
// moving current element to its correct position.
A[ j ] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment