bubbleSort (冒泡排序)
void BubbleSort(int *a, int len)
{
int dwCount,i,j,temp;
for (dwCount=0;dwCount<len-1;dwCount++)//总共要进行len-1步排序
{
for (i=len-1;i>dwCount;i--)//不断比较和交换相邻的两个数
{
if (a[i]<a[i-1])
{
temp=a[i];
a[i]=a[i-1];
a[i-1]=temp;
}
}
printf("第%d步排序结果是:",dwCount+1);
for(j=0;j<len;j++ )
{
printf("%d ",a[j]);
}
printf("\n");
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int a[10]={15,26,11,56,45,82,13,20,99,17};
BubbleSort(a,10);
}
参考http://blog.csdn.net/cghver/article/details/7462155