Skip to content

Instantly share code, notes, and snippets.

@mrv1k
Last active May 2, 2017 18:25
Show Gist options
  • Save mrv1k/dfe14043706d2c4aa1daf22886a0ef16 to your computer and use it in GitHub Desktop.
Save mrv1k/dfe14043706d2c4aa1daf22886a0ef16 to your computer and use it in GitHub Desktop.
Bubble sort in C
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