Last active
May 2, 2017 18:25
-
-
Save mrv1k/dfe14043706d2c4aa1daf22886a0ef16 to your computer and use it in GitHub Desktop.
Bubble sort in C
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 sort(int values[], int n) | |
{ | |
for (int i = 0; i < n; i++) | |
{ | |
for (int j = 0; j < (n - i - 1); j++) { | |
if (values[j] > values[j + 1]) | |
{ | |
int bubble = values[j]; | |
values[j] = values[j + 1]; | |
values[j + 1] = bubble; | |
} | |
} | |
} | |
// for (int i = 0; i < n; i++) { printf("%i", values[i]); } printf("\n"); // debug | |
} | |
sort(array, arrsize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment