Skip to content

Instantly share code, notes, and snippets.

@YassineBajdou
Created June 6, 2018 20:52
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/e6ee0fd5fd4d777cff283eae5a84be32 to your computer and use it in GitHub Desktop.
Save YassineBajdou/e6ee0fd5fd4d777cff283eae5a84be32 to your computer and use it in GitHub Desktop.
Bubble Sort
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