#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"
void bubblesort_little_first(int a[],int len);
int main(int argc, char* argv[])
{
int a[20];
int i;
srand(time(NULL));
for(i=0;i<20;i++)
a[i] = rand()%100;
printf("before sort:\n");
for(i=0;i<20;i++)
printf("%d\t",a[i]);
printf("\n");
printf("little_first sorting...\n");
bubblesort_little_first(a,sizeof(a)/sizeof(a[0]));
printf("after sort:\n");
for(i=0;i<20;i++)
printf("%d\t",a[i]);
printf("\n");
return 0;
}
void bubblesort_little_first(int a[],int len)
{
int i,j;
for(i=0;i<len-1;i++)
for(j=0;j<len-i-1;j++)
{
if(a[j] > a[j+1])
{
a[j] += a[j+1];
a[j+1] = a[j] - a[j+1];
a[j] = a[j] - a[j+1];
}
}
}
冒泡排序:大泡
最新推荐文章于 2022-11-03 15:38:28 发布