Skip to content

Instantly share code, notes, and snippets.

@tekk
Created July 21, 2014 17:49
Show Gist options
  • Save tekk/7483ad2711ef822b1ff8 to your computer and use it in GitHub Desktop.
Save tekk/7483ad2711ef822b1ff8 to your computer and use it in GitHub Desktop.
Elegant bubblesort, source: Arduino forums
void bsort(int *a, int n)
{
for (int i = 1; i < n; ++i)
{
int j = a[i];
int k;
for (k = i - 1; (k >= 0) && (j < a[k]); k--)
{
a[k + 1] = a[k];
}
a[k + 1] = j;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment