冒泡排序多少个都能排,这个是由小到大排
# include
# include
//输入数组
void input(float * pArr, int len)
{
int i = 0;
for (i=0; i
printf("请输入第%d个数: ", i+1);
scanf("%f", &pArr[i]);
}
return;
}
//排序 冒泡法
void sort (float * a, int len)
{
int i, j, t;
for (i=0; i
for (j=0; j
if (a[j]>a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
}
return;
}
int main (void)
{
float *p;
int m,len, i;
char ch;
do{
printf("请输入您要排序数字的个数: ");
scanf("%d", &len);
p = (float *)malloc(len*sizeof(float));//动态内存放p数组
input(p, len);
sort(p, len);
for (m=0; m
printf("\n");
free(p);
printf("请问是否继续?Y/N ");
scanf(" %c", &ch);
}while ('Y' == ch || 'y' == ch);
return 0;
}