#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;
}
冒泡排序。
![](https://img-home.csdnimg.cn/images/20240711042549.png)