#include <iostream>
using namespace std;
int main() {
int a[100], n, j, t;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n - 1; i++) {
for (int j = 0; j <= n - 1 - i; j++) {
if (a[j] > a[j + 1]) {
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
}
C++冒泡排序
最新推荐文章于 2024-11-17 15:19:52 发布