#include using namespace std;

void bubbleSort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } }

int main() { int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; } bubbleSort(arr, n); for (int i = 0; i < n; i++) { cout << arr[i]; if (i != n - 1) { cout << ','; } } return 0; }

C++ 冒泡排序算法:数组元素从小到大排序

原文地址: https://www.cveoy.top/t/topic/n6Bj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录