Created
June 6, 2018 20:52
-
-
Save YassineBajdou/e6ee0fd5fd4d777cff283eae5a84be32 to your computer and use it in GitHub Desktop.
Bubble Sort
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 bubble_sort( int A[ ], int n ) { | |
int temp; | |
for(int k = 0; k< n-1; k++) { | |
// (n-k-1) is for ignoring comparisons of elements which have already been compared in earlier iterations | |
for(int i = 0; i < n-k-1; i++) { | |
if(A[ i ] > A[ i+1] ) { | |
// here swapping of positions is being done. | |
temp = A[ i ]; | |
A[ i ] = A[ i+1 ]; | |
A[ i + 1] = temp; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment