#include<stdio.h>
#define N 5
int main()
{
int t;
int a[N] = { 12,5,23,6,2 };
printf("原始数据:\n");
for (int i = 0; i < N; i++)
{
printf("%d\n", a[i]);
}
for (int i = 0; i < N - 1; i++)
{
for (int j = 0; j < N - 1 - i; j++)
{
if (a[j] > a[j + 1])//若改为小于,则变为从上到下降序排列
{
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
printf("排序后的数据:\n");
for (int i = 0; i < N; i++)
{
printf("%d\n", a[i]);
}
return 0;
}
C语言:Bubble Sorting(冒泡排序)
于 2023-11-17 23:40:11 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)