#include<stdio.h>
void bubble_stor(int arr[], int len)
{
for (int i = 0; i < len - 1; i++)
for (int j = 0; j < len - 1 - i; j++)
{
int temp;
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}int main(void)
{
int arr[] = { 5, 3, 1, 6, 4, 7, 9, 8, 2, 10 };
int len = sizeof(arr) / sizeof(arr[0]);
bubble_stor(arr, len);
for (int i = 0; i < len; i++)
printf("%d ", arr[i]);
return 0;
}
C语言——冒泡排序
于 2023-08-22 10:20:58 首次发布