#include
void bubble_sort(int a[], int len)
{
int i, j;
int temp = 0;
for(i = 0; i < len-2; i++)
{
for(j = len-2; j >= i; j-- )
{
if(a[j+1] < a[j])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
int main(void)
{
int i;
int a[] = {1, 5, 7, 6, 8, 2};
bubble_sort(a, sizeof(a)/sizeof(a[0]));
for(i = 0; i < sizeof(a)/sizeof(a[0]); i++)
{
printf("%d ", a[i]);
}
printf("\n");
return 0;
}
阅读(687) | 评论(0) | 转发(0) |