您的位置:首页 > 其它

冒泡排序

2016-08-18 21:37 246 查看
不多说,来自学长的挑战。

/*************************
*Bubble Sort            *
*                 by:ZCB*
*************************/

#include<stdio.h>
#include<stdlib.h>

int main(void)
{
int a[100];
int b = 0;
int c = 1;
int d = 0;
int i = 0;
printf("请输入要排序的数字.\n");
printf("每输入一个数字请按Enter键确认.\n");
printf("输入完毕后请输入0再按Enter键确认.\n");
do
{
scanf("%d",&a[i]);
i++;
}
while(a[i - 1] != 0);
while(c != 0)
{
b = 0;
c = 0;
while(b < i - 2)
{
if(a[b] > a[b + 1])
{
int temp = a[b];
a[b] = a[b + 1];
a[b + 1] = temp;
c++;
}
b++;
}
}
printf("排序如下:\n");
for(;d < i - 1;d++)
{
printf("%d\n",a[d]);
}
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: