'commit'
This commit is contained in:
19
TangDou/LuoGuBook/L9_2_BubbleSort_BigToSmall.cpp
Normal file
19
TangDou/LuoGuBook/L9_2_BubbleSort_BigToSmall.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user