提交时间:2024-08-19 23:19:39
运行 ID: 168169
#include <iostream> #include <vector> using namespace std; void bubbleSort(int arr[],int n) { bool swapped; for (int i = 0; i < n-1; i++) { swapped = false; for (int j = 0; j < n-i-1; j++) { if (arr[j] > arr[j+1]) { swap(arr[j], arr[j+1]); swapped = true; } } if (!swapped) break; } } int main() { int n; cin>>n; int numbers[n]; for (int i=0;i<n;i++) cin>>numbers[i]; bubbleSort(numbers,n); for (int i=0;i<n;i++) cout<<numbers[i]<<" "; return 0; }