http://baike.baidu.com/view/254413.htm
http://blog.csdn.net/morewindows/article/details/6657829
#include <stdio.h>
#include <stdlib.h>
int bubble_sort(int array[], int num)
{
int i, j, temp;
if(NULL == array) return -1;
for (i = 0; i < num; i++) {
for (j = num - 1; j > i; j--) {
if (array[j] < array[j-1]) { //升序
temp = array[j-1];
array[j-1] = array[j];
array[j] = temp;
}
}
}
return 0;
}
void main()
{
int i;
int num_array[20];
srand(0);
printf("\r\n init: ");
for(i = 0; i < 20; i++) {
num_array[i] = rand()%1000;
printf("%d ", num_array[i]);
}
bubble_sort(num_array, 20);
printf("\r\n bubble sort: ");
for(i = 0; i < 20; i++) {
printf("%d ", num_array[i]);
}
}