#include <stdio.h>
#include <time.h>
static void BubbleSort(int *shuzu);
void main()
{
system("clear");
int i=0;
int shuzu[11];
srand((unsigned int)time(NULL));
for(i=0;i<=10;i++)
{
shuzu[i]=rand()%100;
}
printf("Original is \n");
for(i=0;i<=10;i++)
{
printf("%d ",shuzu[i]);
}
printf("\n\n\n");
BubbleSort(shuzu);
}
static void BubbleSort(int *shuzu)
{
int i=0,j=0,k=0;
int temp=0;
for(i=0;i<=10;i++)
{
for(j=10;j>=i;j--)
{
if(shuzu[j-1]>shuzu[j])
{
temp=shuzu[j];
shuzu[j]=shuzu[j-1];
shuzu[j-1]=temp;
}
for(k=0;k<=10;k++)
{
printf("%d ",*(shuzu+k));
}
printf("\n");
}
printf("the %d round end\n",i);
}
printf("\nafter BubbleSort \n");
for(i=0;i<=10;i++)
{
printf("%d ",*(shuzu+i));
}
printf("\n");
}
c语言数组--冒泡排序
最新推荐文章于 2024-01-08 14:49:44 发布