标签:for 算法 style ble 排序 main sort 冒泡 bubble
冒泡排序
#include <stdio.h>
void bubble_sort(int a[],int n)
{
int i,j,temp;
for(i = 0; i < n-1; i++)
for(j = 0; j < n-1-i; j++)
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
return ;
}
int main(void)
{
int i;
int a[5] = {8,3,2,9,7};
//进行冒泡排序
bubble_sort(a,5);
//输出排序后的数据
for(i = 0; i < 5; i++)
printf("%d ",a[i]);
return 0;
}
标签:for 算法 style ble 排序 main sort 冒泡 bubble
原文地址:http://www.cnblogs.com/xiaoshi-com/p/6198915.html