You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
477 B
20 lines
477 B
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
|
|
int a[] = {1, 3, 5, 7, 9, 2, 4, 6, 8}; // 待排序数组
|
|
|
|
int main() {
|
|
int len = sizeof(a) / sizeof(int); // 数组长度
|
|
|
|
// 冒泡排序
|
|
for (int i = 0; i < len; i++)
|
|
for (int j = 0; j < len - 1 - i; j++)
|
|
if (a[j] < a[j + 1]) // 从大排到小
|
|
swap(a[j], a[j + 1]);
|
|
|
|
// 打印数组
|
|
for (int i = 0; i < len; i++) cout << a[i] << " ";
|
|
|
|
return 0;
|
|
}
|