Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nixeagle/424954 to your computer and use it in GitHub Desktop.
Save nixeagle/424954 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int bubblesort(int *arr, int len)
{
int i;
int changed;
int done = FALSE;
while (!done)
{ changed = FALSE;
for (i = 0; i < len-1; i++)
{ if (arr[i] > arr[i+1])
{ tmp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = arr[i];
changed = TRUE; } }
if (!changed)
{ done = TRUE; } } }
int main()
{
int arr[5] = {9,3,4,1,2};
bubblesort(arr, 5);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment