c语言实现冒泡法排序,如下:
因为c语言中没有bool类型,注意引用时的头文件声明TRUE和FALSE值分别为1和0:
void _bubbleSort(int a[],int length)
{
int i,j,temp;
int bools;
bools = TRUE;
for(i=0;i<length-1 && bools;++i)
{
bools = FALSE;
for(j=0;j<length-i;++j)
{
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
bools = TRUE;
}
}
}
}
因为c语言中没有bool类型,注意引用时的头文件声明TRUE和FALSE值分别为1和0:
#define TRUE 1
#define FALSE 0