#include <stdio.h>
#define SIZE 10
int main()
{
int temp,x,i,j,y;
int count = 0;
int arr[SIZE] = { 10,7,1,5,2,4,6,3,8,9 };// 十个数的无序排列
for ( x = 0; x < SIZE; x++)
{
printf("原数组为:%d \n", arr[x]);
}
for ( i = 0; i < SIZE - 1; i++) // n个数的数列总扫描 n - 1次
{
for ( j = 0; j < SIZE - i - 1; j++) // 每一趟扫描到arr[n-i-2] 与arr[n-i-1]的位置
{
if (arr[j] > arr[j + 1])
{
// 交换操作
temp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = temp;
}
}
}
for ( y = 0; y < SIZE; y++)
{
printf("排序之后的数组为:%d \n", arr[y]);
}
return 0;
}
冒泡排序。
最新推荐文章于 2026-06-17 23:49:13 发布
这是一个C语言程序,它展示了如何使用冒泡排序算法对一个无序的整数数组进行排序。程序首先打印原始数组,然后通过两层循环实现冒泡排序,将较大的元素逐渐‘冒’到数组末尾,最后输出排序后的数组。
9万+

被折叠的 条评论
为什么被折叠?



