程序:冒泡排序

时间:2023-01-04 20:58:52
#include<stdio.h>
void bubble_sort(int arr[], int sz)
{
int a = 0;
for (a = 0; a < sz - 1; a++)
{
int b = 0;
for (b = 0; b < sz - 1 - a; b++)
{
if (arr[b] >= arr[b + 1])
{
int c = arr[b];
arr[b] = arr[b + 1];
arr[b + 1] = c;
}
}
}
}
int main()
{
int i = 0;
int arr[] = { 10,9,8,7,6,5,4,3,2,1 };
int sz = sizeof(arr) / sizeof(arr[0]);
bubble_sort(arr, sz);
for (i = 0; i <= sz-1; i++)
{
printf("%d ", arr[i]);
}
return 0;
}

程序:冒泡排序