Created
November 8, 2018 08:49
-
-
Save YassineBajdou/df3cd8e47a111a83076202b67f6db4a4 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 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