#include <iostream>
using namespace std;
void bubble_sort(int a[], int n)
{
int t;
for (int i = 0; i < n - 1; i++)
{
for (int j = 0; j < n - i - 1; j++)
{
if (a[j] > a[j + 1])
{
swap(a[j], a[j + 1]);
}
}
}
}
int main() {
int arr[] = { 61, 17, 29, 22, 34, 60, 72, 21, 50, 1, 62 };
int len = (int)sizeof(arr) / sizeof(*arr);
bubble_sort(arr, len);
for (auto& a:arr) cout << a << ' ';
cout << endl;
return 0;
}
十大排序算法之一(冒泡排序)
最新推荐文章于 2024-05-20 20:08:58 发布