现在的位置: 首页 > 综合 > 正文

数据结构之冒泡排序的实现(C语言)

2013年10月05日 ⁄ 综合 ⁄ 共 356字 ⁄ 字号 评论关闭
#include <stdio.h>
void BubbleSort(int *a, int len)
{
	int count,i,j,temp;
   for (count=0;count<len-1;count++)//总共要进行len-1步排序
   {
	   for (i=len-1;i>count;i--)//不断比较和交换相邻的两个数
	   {
		   if (a[i]<a[i-1])
		   {
               temp=a[i];
			   a[i]=a[i-1];
			   a[i-1]=temp;
		   }
	   }
	   printf("第%d步排序结果是:",count+1);
	   for(j=0;j<len;j++ )
	   {
           printf("%d ",a[j]);

	   }
	   printf("\n");
   }
}
void main()
{
	int a[10]={15,26,11,56,45,82,13,20,99,17};
	BubbleSort(a,10);
}

抱歉!评论已关闭.