Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created February 5, 2014 00:44
Show Gist options
  • Save kotaroito/8815386 to your computer and use it in GitHub Desktop.
Save kotaroito/8815386 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#define N 10
void bubbleSort(int num, int sort[])
{
int i, j, tmp, flag;
j = 0;
do {
flag = 0;
for ( i = 0; i < num - 1 - j; i++ ) {
if ( sort[i] > sort[i + 1] ) {
tmp = sort[i + 1];
sort[i + 1] = sort[i];
sort[i] = tmp;
flag = 1;
}
}
j++;
} while ( flag == 1 );
}
int main(void)
{
int i;
int sort[N];
srand((unsigned int) time(NULL));
for ( i = 0; i < N; i++ ) {
sort[i] = rand();
}
bubbleSort(N, sort);
for ( i = 0; i < N; i++ ) {
printf("%010d ", sort[i]);
}
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment